line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2013-2019 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
|
|
|
|
|
|
# This code is part of distribution Any-Daemon-HTTP. Meta-POD processed |
6
|
|
|
|
|
|
|
# with OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Any::Daemon::HTTP::VirtualHost; |
10
|
1
|
|
|
1
|
|
7
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.28'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
15
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
use Log::Report 'any-daemon-http'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
675
|
use Any::Daemon::HTTP::Directory; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
71
|
|
20
|
1
|
|
|
1
|
|
579
|
use Any::Daemon::HTTP::UserDirs; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
21
|
1
|
|
|
1
|
|
434
|
use Any::Daemon::HTTP::Proxy; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
7
|
use HTTP::Status qw/:constants/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
376
|
|
24
|
1
|
|
|
1
|
|
8
|
use List::Util qw/first/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
68
|
|
25
|
1
|
|
|
1
|
|
9
|
use File::Spec (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
26
|
1
|
|
|
1
|
|
6
|
use POSIX::1003 qw(strftime); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
27
|
1
|
|
|
1
|
|
391
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
28
|
1
|
|
|
1
|
|
6
|
use Digest::MD5 qw(md5_base64); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2800
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new(@) |
32
|
0
|
|
|
0
|
1
|
|
{ my $class = shift; |
33
|
0
|
0
|
|
|
|
|
my $args = @_==1 ? shift : {@_}; |
34
|
0
|
|
|
|
|
|
(bless {}, $class)->init($args); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub init($) |
38
|
0
|
|
|
0
|
0
|
|
{ my ($self, $args) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $name = $self->{ADHV_name} = $args->{name}; |
41
|
0
|
0
|
|
|
|
|
defined $name |
42
|
|
|
|
|
|
|
or error __x"virtual host {pkg} has no name", pkg => ref $self; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
0
|
|
|
|
my $aliases = $args->{aliases} || 'AUTO'; |
45
|
|
|
|
|
|
|
$self->{ADHV_aliases} |
46
|
0
|
0
|
|
|
|
|
= ref $aliases eq 'ARRAY' ? $aliases |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
47
|
|
|
|
|
|
|
: $aliases eq 'AUTO' ? [ $self->generateAliases($name) ] |
48
|
|
|
|
|
|
|
: defined $aliases ? [ $aliases ] |
49
|
|
|
|
|
|
|
: []; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
0
|
|
|
|
$self->addHandler($args->{handlers} || $args->{handler}); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$self->{ADHV_rewrite} = $self->_rewrite_call($args->{rewrite}); |
54
|
0
|
|
|
|
|
|
$self->{ADHV_redirect} = $self->_redirect_call($args->{redirect}); |
55
|
0
|
|
|
|
|
|
$self->{ADHV_udirs} = $self->_user_dirs($args->{user_dirs}); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->{ADHV_sources} = {}; |
58
|
0
|
|
|
|
|
|
$self->_auto_docs($args->{documents}); |
59
|
0
|
|
0
|
|
|
|
my $dirs = $args->{directories} || $args->{directory} || []; |
60
|
0
|
0
|
|
|
|
|
$self->addDirectory($_) for ref $dirs eq 'ARRAY' ? @$dirs : $dirs; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$self->{ADHV_proxies} = {}; |
63
|
0
|
|
0
|
|
|
|
my $proxies = $args->{proxies} || $args->{proxy} || []; |
64
|
0
|
0
|
|
|
|
|
$self->addProxy($_) for ref $proxies eq 'ARRAY' ? @$proxies : $proxies; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _user_dirs($) |
70
|
0
|
|
|
0
|
|
|
{ my ($self, $dirs) = @_; |
71
|
0
|
0
|
|
|
|
|
$dirs or return undef; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
return Any::Daemon::HTTP::UserDirs->new($dirs) |
74
|
|
|
|
|
|
|
if ref $dirs eq 'HASH'; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
return $dirs |
77
|
|
|
|
|
|
|
if $dirs->isa('Any::Daemon::HTTP::UserDirs'); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
error __x"vhost {name} user_dirs is not an ::UserDirs object" |
80
|
|
|
|
|
|
|
, name => $self->name; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _auto_docs($) |
84
|
0
|
|
|
0
|
|
|
{ my ($self, $docroot) = @_; |
85
|
0
|
0
|
|
|
|
|
$docroot or return; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
File::Spec->file_name_is_absolute($docroot) |
88
|
|
|
|
|
|
|
or error __x"vhost {name} documents directory must be absolute" |
89
|
|
|
|
|
|
|
, name => $self->name; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
-d $docroot |
92
|
|
|
|
|
|
|
or error __x"vhost {name} documents `{dir}' must point to dir" |
93
|
|
|
|
|
|
|
, name => $self->name, dir => $docroot; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$docroot =~ s/\\$//; # strip trailing / if present |
96
|
0
|
|
|
|
|
|
$self->addDirectory(path => '/', location => $docroot); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#--------------------- |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
1
|
|
sub name() {shift->{ADHV_name}} |
102
|
0
|
|
|
0
|
1
|
|
sub aliases() {@{shift->{ADHV_aliases}}} |
|
0
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub generateAliases($) |
106
|
0
|
|
|
0
|
1
|
|
{ my ($thing, $h) = @_; |
107
|
0
|
|
|
|
|
|
my @a; |
108
|
0
|
|
|
|
|
|
$h =~ m/^(([^.:]+)(?:[^:]*)?)(?:\:([0-9]+))?$/; |
109
|
0
|
0
|
|
|
|
|
push @a, $1 if $3; # name with port |
110
|
0
|
0
|
|
|
|
|
push @a, $2 if $1 ne $2; # hostname vs fqdn |
111
|
0
|
0
|
0
|
|
|
|
push @a, "$2:$3" if $1 ne $2 && $3; # hostname with port |
112
|
0
|
|
|
|
|
|
@a; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
#--------------------- |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub addHandler(@) |
118
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
119
|
0
|
0
|
0
|
|
|
|
return if @_==1 && !defined $_[0]; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my @pairs |
122
|
|
|
|
|
|
|
= @_ > 1 ? @_ |
123
|
0
|
0
|
|
|
|
|
: ref $_[0] eq 'HASH' ? %{$_[0]} |
|
0
|
0
|
|
|
|
|
|
124
|
|
|
|
|
|
|
: ( '/' => $_[0]); |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
0
|
|
|
|
my $h = $self->{ADHV_handlers} ||= {}; |
127
|
0
|
|
|
|
|
|
while(@pairs) |
128
|
0
|
|
|
|
|
|
{ my $k = shift @pairs; |
129
|
0
|
0
|
|
|
|
|
substr($k, 0, 1) eq '/' |
130
|
|
|
|
|
|
|
or error __x"handler path must be absolute, for {rel} in {vhost}" |
131
|
|
|
|
|
|
|
, rel => $k, vhost => $self->name; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $v = shift @pairs; |
134
|
0
|
0
|
|
|
|
|
unless(ref $v) |
135
|
0
|
|
|
|
|
|
{ my $method = $v; |
136
|
0
|
0
|
|
|
|
|
$self->can($method) |
137
|
|
|
|
|
|
|
or error __x"handler method {name} not provided by {vhost}" |
138
|
|
|
|
|
|
|
, name => $method, vhost => ref $self; |
139
|
0
|
|
|
0
|
|
|
$v = sub { shift->$method(@_) }; |
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$h->{$k} = $v; |
143
|
|
|
|
|
|
|
} |
144
|
0
|
|
|
|
|
|
$h; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
*addHandlers = \&addHandler; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub findHandler(@) |
152
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
153
|
0
|
0
|
|
|
|
|
my @path = @_>1 ? @_ : ref $_[0] ? $_[0]->path_segments : split('/', $_[0]); |
|
|
0
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
0
|
|
0
|
|
|
|
my $h = $self->{ADHV_handlers} ||= {}; |
156
|
0
|
|
|
|
|
|
while(@path) |
157
|
0
|
|
|
|
|
|
{ my $handler = $h->{join '/', @path}; |
158
|
0
|
0
|
|
|
|
|
return $handler if $handler; |
159
|
0
|
|
|
|
|
|
pop @path; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
if(my $handler = $h->{'/'}) |
163
|
0
|
|
|
|
|
|
{ return $handler; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
0
|
|
|
sub { HTTP::Response->new(HTTP_NOT_FOUND) }; |
|
0
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub handleRequest($$$;$) |
171
|
0
|
|
|
0
|
1
|
|
{ my ($self, $server, $session, $req, $uri) = @_; |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
0
|
|
|
|
$uri ||= $req->uri; |
174
|
0
|
|
|
|
|
|
my $new_uri = $self->rewrite($uri); |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
if(my $redir = $self->mustRedirect($new_uri)) |
177
|
0
|
|
|
|
|
|
{ return $redir; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
0
|
0
|
|
|
|
|
if($new_uri ne $uri) |
181
|
0
|
|
|
|
|
|
{ info __x"{vhost} rewrote {uri} into {new}" |
182
|
|
|
|
|
|
|
, vhost => $self->name, uri => $uri, new => $new_uri; |
183
|
0
|
|
|
|
|
|
$uri = $new_uri; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
my $path = $uri->path; |
187
|
0
|
|
|
|
|
|
info __x"{vhost} request {path}", vhost => $self->name, path => $uri->path; |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
my @path = $uri->path_segments; |
190
|
0
|
|
|
|
|
|
my $source = $self->sourceFor(@path); |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# static content? |
193
|
0
|
0
|
|
|
|
|
my $resp = $source ? $source->collect($self, $session, $req,$uri) : undef; |
194
|
0
|
0
|
|
|
|
|
return $resp if $resp; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# dynamic content |
197
|
0
|
|
|
|
|
|
$resp = $self->findHandler(@path)->($self, $session, $req, $uri, $source); |
198
|
0
|
0
|
|
|
|
|
$resp or return HTTP::Response->new(HTTP_NO_CONTENT); |
199
|
|
|
|
|
|
|
|
200
|
0
|
0
|
0
|
|
|
|
blessed $resp && $resp->isa('HTTP::Response') |
201
|
|
|
|
|
|
|
or error __x"Handler for {uri} does not return an HTTP::Response", |
202
|
|
|
|
|
|
|
uri => $uri->as_string; |
203
|
|
|
|
|
|
|
|
204
|
0
|
0
|
|
|
|
|
$resp->code eq HTTP_OK |
205
|
|
|
|
|
|
|
or return $resp; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
# cache dynamic content based on md5 checksum |
208
|
0
|
|
|
|
|
|
my $etag = md5_base64 ${$resp->content_ref}; |
|
0
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
my $has_etag = $req->headers->header('ETag'); |
210
|
0
|
0
|
0
|
|
|
|
return HTTP::Response->new(HTTP_NOT_MODIFIED, 'cached dynamic data') |
211
|
|
|
|
|
|
|
if $has_etag && $has_etag eq $etag; |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
$resp->headers->header(ETag => $etag); |
214
|
0
|
|
|
|
|
|
$resp; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
#---------------------- |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
0
|
1
|
|
sub rewrite($) { $_[0]->{ADHV_rewrite}->(@_) } |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub _rewrite_call($) |
222
|
0
|
|
|
0
|
|
|
{ my ($self, $rew) = @_; |
223
|
0
|
0
|
|
0
|
|
|
$rew or return sub { $_[1] }; |
|
0
|
|
|
|
|
|
|
224
|
0
|
0
|
|
|
|
|
return $rew if ref $rew eq 'CODE'; |
225
|
|
|
|
|
|
|
|
226
|
0
|
0
|
|
|
|
|
if(ref $rew eq 'HASH') |
227
|
0
|
|
|
|
|
|
{ my %lookup = %$rew; |
228
|
|
|
|
|
|
|
return sub { |
229
|
0
|
0
|
|
0
|
|
|
my $uri = $_[1] or return undef; |
230
|
0
|
0
|
|
|
|
|
exists $lookup{$uri->path} or return $uri; |
231
|
0
|
|
|
|
|
|
URI->new_abs($lookup{$uri->path}, $uri) |
232
|
0
|
|
|
|
|
|
}; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
0
|
0
|
|
|
|
|
if(!ref $rew) |
236
|
0
|
|
|
0
|
|
|
{ return sub {shift->$rew(@_)} |
237
|
0
|
0
|
|
|
|
|
if $self->can($rew); |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
error __x"rewrite rule method {name} in {vhost} does not exist" |
240
|
|
|
|
|
|
|
, name => $rew, vhost => $self->name; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
0
|
|
0
|
|
|
|
error __x"unknown rewrite rule type {ref} in {vhost}" |
244
|
|
|
|
|
|
|
, ref => (ref $rew || $rew), vhost => $self->name; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub redirect($;$) |
249
|
0
|
|
|
0
|
1
|
|
{ my ($self, $uri, $code) = @_; |
250
|
0
|
|
0
|
|
|
|
HTTP::Response->new($code//HTTP_TEMPORARY_REDIRECT, undef |
251
|
|
|
|
|
|
|
, [ Location => "$uri" ] |
252
|
|
|
|
|
|
|
); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub mustRedirect($) |
257
|
0
|
|
|
0
|
1
|
|
{ my ($self, $uri) = @_; |
258
|
0
|
|
|
|
|
|
my $new_uri = $self->{ADHV_redirect}->($self, $uri); |
259
|
0
|
0
|
0
|
|
|
|
$new_uri && $new_uri ne $uri or return; |
260
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
|
info __x"{vhost} redirecting {uri} to {new}" |
262
|
|
|
|
|
|
|
, vhost => $self->name, uri => $uri->path, new => "$new_uri"; |
263
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
|
$self->redirect($new_uri); |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub _redirect_call($) |
268
|
0
|
|
|
0
|
|
|
{ my ($self, $red) = @_; |
269
|
0
|
0
|
|
0
|
|
|
$red or return sub { $_[1] }; |
|
0
|
|
|
|
|
|
|
270
|
0
|
0
|
|
|
|
|
return $red if ref $red eq 'CODE'; |
271
|
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
if(ref $red eq 'HASH') |
273
|
0
|
|
|
|
|
|
{ my %lookup = %$red; |
274
|
|
|
|
|
|
|
return sub { |
275
|
0
|
0
|
|
0
|
|
|
my $uri = $_[1] or return undef; |
276
|
0
|
0
|
|
|
|
|
exists $lookup{$uri->path} or return undef; |
277
|
0
|
|
|
|
|
|
URI->new_abs($lookup{$uri->path}, $uri); |
278
|
0
|
|
|
|
|
|
}; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
0
|
0
|
|
|
|
|
if(!ref $red) |
282
|
0
|
|
|
0
|
|
|
{ return sub {shift->$red(@_)} |
283
|
0
|
0
|
|
|
|
|
if $self->can($red); |
284
|
|
|
|
|
|
|
|
285
|
0
|
|
|
|
|
|
error __x"redirect rule method {name} in {vhost} does not exist" |
286
|
|
|
|
|
|
|
, name => $red, vhost => $self->name; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
0
|
|
0
|
|
|
|
error __x"unknown redirect rule type {ref} in {vhost}" |
290
|
|
|
|
|
|
|
, ref => (ref $red || $red), vhost => $self->name; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
sub addSource($) |
295
|
0
|
|
|
0
|
1
|
|
{ my ($self, $source) = @_; |
296
|
0
|
0
|
|
|
|
|
$source or return; |
297
|
|
|
|
|
|
|
|
298
|
0
|
|
|
|
|
|
my $sources = $self->{ADHV_sources}; |
299
|
0
|
|
|
|
|
|
my $path = $source->path; |
300
|
|
|
|
|
|
|
|
301
|
0
|
0
|
|
|
|
|
if(my $old = exists $sources->{$path}) |
302
|
0
|
|
|
|
|
|
{ error __x"vhost {name} directory `{path}' defined twice, for `{old}' and `{new}' " |
303
|
|
|
|
|
|
|
, name => $self->name, path => $path |
304
|
|
|
|
|
|
|
, old => $old->name, new => $source->name; |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
0
|
|
|
|
|
|
info __x"add configuration `{name}' to {vhost} for {path}" |
308
|
|
|
|
|
|
|
, name => $source->name, vhost => $self->name, path => $path; |
309
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
|
$sources->{$path} = $source; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
#------------------ |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
sub filename($) |
316
|
0
|
|
|
0
|
1
|
|
{ my ($self, $uri) = @_; |
317
|
0
|
|
|
|
|
|
my $dir = $self->sourceFor($uri); |
318
|
0
|
0
|
|
|
|
|
$dir ? $dir->filename($uri->path) : undef; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub addDirectory(@) |
323
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
324
|
0
|
0
|
0
|
|
|
|
my $dir = @_==1 && blessed $_[0] ? shift |
325
|
|
|
|
|
|
|
: Any::Daemon::HTTP::Directory->new(@_); |
326
|
|
|
|
|
|
|
|
327
|
0
|
|
|
|
|
|
$self->addSource($dir); |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
sub sourceFor(@) |
332
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
333
|
0
|
0
|
0
|
|
|
|
my @path = @_>1 || index($_[0], '/')==-1 ? @_ : split('/', $_[0]); |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
return $self->{ADHV_udirs} |
336
|
0
|
0
|
|
|
|
|
if substr($path[0], 0, 1) eq '~'; |
337
|
|
|
|
|
|
|
|
338
|
0
|
|
|
|
|
|
my $sources = $self->{ADHV_sources}; |
339
|
0
|
|
|
|
|
|
while(@path) |
340
|
0
|
|
|
|
|
|
{ my $dir = $sources->{join '/', @path}; |
341
|
0
|
0
|
|
|
|
|
return $dir if $dir; |
342
|
0
|
|
|
|
|
|
pop @path; |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
# return empty list, not undef, when not found |
346
|
0
|
0
|
|
|
|
|
$sources->{'/'} ? $sources->{'/'} : (); |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
#----------------------------- |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
sub addProxy(@) |
352
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
353
|
0
|
0
|
0
|
|
|
|
my $proxy = @_==1 && blessed $_[0] ? shift |
354
|
|
|
|
|
|
|
: Any::Daemon::HTTP::Proxy->new(@_); |
355
|
|
|
|
|
|
|
|
356
|
0
|
0
|
|
|
|
|
error __x"proxy {name} has a map, so cannot be added to a vhost" |
357
|
|
|
|
|
|
|
, name => $proxy->name |
358
|
|
|
|
|
|
|
if $proxy->forwardMap; |
359
|
|
|
|
|
|
|
|
360
|
0
|
|
|
|
|
|
info __x"add proxy configuration to {vhost} for {path}" |
361
|
|
|
|
|
|
|
, vhost => $self->name, path => $proxy->path; |
362
|
|
|
|
|
|
|
|
363
|
0
|
|
|
|
|
|
$self->addSource($proxy); |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
#----------------------------- |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
1; |