André Malo wrote:
In order to switch between different server configurations by just supplying
another Host header, it'd be useful to have name based VHs in our testsuite.
The attached patch tries to solve this problem. The Syntax is like

<VirtualHost servername:module>
...
</VirtualHost>

If servername is not _default_, the above will be transformed to:

Listen $port
NameVirtualHost *:$port
<VirtualHost *:$port>
    ServerName $servername:$port (or 1.3 like, however)
    ...
</VirtualHost>

A sample input and transformation are also attached. Opinions?

+1, but see a few minor code comments below

+++ httpd-test/Apache-Test/lib/Apache/TestConfig.pm
[...]
    #extra config that should go *inside* the <VirtualHost ...>
-    my @in_config = $self->servername_config($vars->{servername},
+    my @in_config = $self->servername_config($namebased
+                                               ? $namebased
+                                               : $vars->{servername},
                                             $port);

indent 4 please

-    #extra config that should go *outside* the <VirtualHost ...>
-    my @out_config = ([Listen => $port]);
+    my @out_config;

should be:

my @out_config = ();

since it might be used later without anything pushed in (so it'd be undef).

+    if ($self->{vhosts}->{$module}->{namebased} < 2) {
+        #extra config that should go *outside* the <VirtualHost ...>
+        @out_config = ([Listen => $port]);

but originally that code was always running, why it's conditioned? shouldn't it always run?


@@ -989,7 +999,8 @@
        #used when parsing *.conf.in files
        in_string     => $form_string->($double_indent, @in_config),
        out_string    => $form_string->($indent, @out_config),
-        line          => "$indent<VirtualHost _default_:$port>",
+        line          => "$indent<VirtualHost ". ($namebased? '*': 
'_default_').
+                         ":$port>",

indent:

+ line => "$indent<VirtualHost " . ($namebased ? '*' : '_default_').



+++ httpd-test/Apache-Test/lib/Apache/TestConfigPerl.pm

sub new_vhost {
-    my($self, $module) = @_;
+    my($self, $module, $namebased) = @_;
+    my ($port, $servername, $vhost);

no space:

my($port, $servername, $vhost);


-    my $port       = $self->server->select_port;
-    my $servername = $self->{vars}->{servername};
-    my $vhost      = $self->{vhosts}->{$module} = {};
+    unless ($namebased and exists $self->{vhosts}->{$module}) {
+        $port       = $self->server->select_port;
+        $vhost      = $self->{vhosts}->{$module} = {};
+
+        $vhost->{port}       = $port;
+        $vhost->{namebased}  = $namebased ? 1 : 0;
+    }
+    else {
+        $vhost      = $self->{vhosts}->{$module};
+        $port       = $vhost->{port};
+        # remember the already configured Listen/NameVirtualHost
+        ++$vhost->{namebased};

normally we used to write i++ in perl, but it's fine as well ;)


__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com



Reply via email to