You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2005/09/03 03:36:27 UTC

sections and A-T autoconfig virtual host expansion magic

Apache-Test automagically assigns port numbers to vhost sections, e.g.:

<VirtualHost myhost>
PerlSetVar foo bar
</VirtualHost>

is expanded to:

Listen 0.0.0.0:8530
<VirtualHost _default_:8530>
     ServerName lapin.stason.org:8530
     PerlSetVar foo bar
</VirtualHost>

But what if I need to use <Perl> inside Vhost, since some values require a 
code to be run? If I do:

<Perl>
my $val = get_val();
$VirtualHost{myhost} = {
    PerlSetVar => ["foo", $bar],
}
</Perl>

A-T won't know to expand it. On the other hand, doing:

<VirtualHost myhost>
<Perl>
   my $val = get_val();
   $PerlSetVar = ["foo", $bar];
</Perl>
/VirtualHost>

is not putting the config into the right vhost (it goes to the top-level 
config.

The only tricky way I've managed to enjoy the both worlds, is using 
add_config:

<Perl>
   use Apache2::ServerUtil ();
   my $val = get_val();
   Apache2::ServerUtil->server->add_config([split /\n/, <<EOI]);
# t/limit/maxx_conn.t
<VirtualHost myhost>
     PerlSetVar foo $var
</VirtualHost>
EOI

</Perl>

I don't see how we can make A-T aware of <Perl> in any other ways. Ideas?


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://mailchannels.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: sections and A-T autoconfig virtual host expansion magic

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> Stas Bekman wrote:
> 
>>Actually
>>
>><VirtualHost gozer>
>><Perl>
>>  $PerlSetVar = "foo $bar";
>></Perl>
>></VirtualHost>
>>
>>works. As I've later figured out thanks to Philippe's examples is that
>>my problem was that I was calling:
>>
>>  $PerlSetVar = ["foo", $bar],
>>
>>which mod_perl has happily ignored or something... it didn't generate
>>any errors. and I think it should.
>>
>>I'm still not sure how to set several PerlSetVar entries.
> 
> 
> @PerlSetVar = ("foo $bar", "fooz $otherbar");
> 
> or
> 
> @PerlSetVar = (['foo',$bar], ['fooz',$otherbar]);

Hmm, so now ['foo', $bar] is Ok for TAKE2? I though you said it had to be 
"foo $bar";

and how does it look as a part of %VirtualHost?

>>It's very confusing. And the worst thing is that things silently fail...
> 
> 
> It doesn't silently fail for me:
> 
> <Perl>
> $PerlSetVar = ['gozer','rules'];
> </Perl>
> 
> $> t/TEST -start
> Syntax error on line 93 of [mp2]/t/conf/extra.last.conf:
> $parms->add_config() has failed: PerlSetVar takes two arguments
> [  error]
> server has died with status 255
> 
> But the attached patche makes it work as you'd expect too ;-)

Cool!

If that's not too much work, mind to add some tests so it's easier to see 
what works?

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://mailchannels.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: sections and A-T autoconfig virtual host expansion magic

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Stas Bekman wrote:
> Actually
> 
> <VirtualHost gozer>
> <Perl>
>   $PerlSetVar = "foo $bar";
> </Perl>
> </VirtualHost>
> 
> works. As I've later figured out thanks to Philippe's examples is that
> my problem was that I was calling:
> 
>   $PerlSetVar = ["foo", $bar],
> 
> which mod_perl has happily ignored or something... it didn't generate
> any errors. and I think it should.
> 
> I'm still not sure how to set several PerlSetVar entries.

@PerlSetVar = ("foo $bar", "fooz $otherbar");

or

@PerlSetVar = (['foo',$bar], ['fooz',$otherbar]);

> It's very confusing. And the worst thing is that things silently fail...

It doesn't silently fail for me:

<Perl>
$PerlSetVar = ['gozer','rules'];
</Perl>

$> t/TEST -start
Syntax error on line 93 of [mp2]/t/conf/extra.last.conf:
$parms->add_config() has failed: PerlSetVar takes two arguments
[  error]
server has died with status 255

But the attached patche makes it work as you'd expect too ;-)

--------------------------------------------------------------------------------
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: sections and A-T autoconfig virtual host expansion magic

Posted by Stas Bekman <st...@stason.org>.
Actually

<VirtualHost gozer>
<Perl>
   $PerlSetVar = "foo $bar";
</Perl>
</VirtualHost>

works. As I've later figured out thanks to Philippe's examples is that my 
problem was that I was calling:

   $PerlSetVar = ["foo", $bar],

which mod_perl has happily ignored or something... it didn't generate any 
errors. and I think it should.

I'm still not sure how to set several PerlSetVar entries.

It's very confusing. And the worst thing is that things silently fail...

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://mailchannels.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: sections and A-T autoconfig virtual host expansion magic

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Geoffrey Young wrote:
>><Perl>
>>my $val = get_val();
>>$VirtualHost{myhost} = {
>>   PerlSetVar => ["foo", $bar],
>>}
>></Perl>
> 
> 
> 
>>I don't see how we can make A-T aware of <Perl> in any other ways. Ideas?
> 
> 
> maybe something like (untested :)
> 
>     $VirtualHost{'_default_:@PORT@'} = {

ok, that won't work - @PORT@ will be wrong.

what about something like this

  <Perl>
    use Apache::Test;
    my $vhost = Apache::Test::config->{vhosts}->{myhost}->{hostport};
    $VirtualHost{$vhost} = {
  ...
  </Perl>

if that doesn't work it probably should :)

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: sections and A-T autoconfig virtual host expansion magic

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> <Perl>
> my $val = get_val();
> $VirtualHost{myhost} = {
>    PerlSetVar => ["foo", $bar],
> }
> </Perl>


> I don't see how we can make A-T aware of <Perl> in any other ways. Ideas?

maybe something like (untested :)

    $VirtualHost{'_default_:@PORT@'} = {

?

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: sections and A-T autoconfig virtual host expansion magic

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Stas Bekman wrote:
> Apache-Test automagically assigns port numbers to vhost sections, e.g.:
> 
> <VirtualHost myhost>
> PerlSetVar foo bar
> </VirtualHost>
> 
> is expanded to:
> 
> Listen 0.0.0.0:8530
> <VirtualHost _default_:8530>
>     ServerName lapin.stason.org:8530
>     PerlSetVar foo bar
> </VirtualHost>
> 
> But what if I need to use <Perl> inside Vhost, since some values require
> a code to be run? If I do:
> 
> <Perl>
> my $val = get_val();
> $VirtualHost{myhost} = {
>    PerlSetVar => ["foo", $bar],
> }
> </Perl>

$val != $bar ??

> A-T won't know to expand it. On the other hand, doing:
> 
> <VirtualHost myhost>
> <Perl>
>   my $val = get_val();
>   $PerlSetVar = ["foo", $bar];
> </Perl>
> /VirtualHost>

That should be:

$PerlSetVar = "foo $val";

And seems to work for me.

<Location /test-gozer>
  PerlHandler My::Gozer
  SetHandler perl-script
</Location>

PerlSetVar gozer "doesn't rule"
<VirtualHost gozer>
<Perl>
  $PerlSetVar = 'gozer rules';
  sub My::Gozer::handler {
    my $r = shift;
    $r->send_http_header('text/plain');
    $r->print("Gozer " . $r->dir_config("gozer") . "\n");
    return Apache2::Const::OK;
  }
</Perl>
</VirtualHost>

$> t/TEST -start
waiting 120 seconds for server to start: ok (waited 13 secs)
server localhost:8529 started
server localhost:8530 listening (filter_out_apache)
server localhost:8531 listening (gozer)
[...]

$> GET http://localhost:8529/test-gozer
Gozer doesn't rule
$> GET http://localhost:8531/test-gozer
Gozer rules

> is not putting the config into the right vhost (it goes to the top-level
> config.
> 
> The only tricky way I've managed to enjoy the both worlds, is using
> add_config:
> 
> <Perl>
>   use Apache2::ServerUtil ();
>   my $val = get_val();
>   Apache2::ServerUtil->server->add_config([split /\n/, <<EOI]);
> # t/limit/maxx_conn.t
> <VirtualHost myhost>
>     PerlSetVar foo $var
> </VirtualHost>
> EOI
> 
> </Perl>

$val != $var again ;-)

> I don't see how we can make A-T aware of <Perl> in any other ways. Ideas?

The correct way would seem to be

<VirtualHost>
  [...]
  <Perl>
    [...]
  </Perl>
  [...]
</VirtualHost>

And it seems to be working.

-- 
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