1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
use strict;
use warnings;
use Net::HTTP::Spore::Request;
use Test::More;
my @tests = (
{
host => 'localhost',
base => 'http://localhost/'
},
{
script_name => '/foo',
host => 'localhost',
base => 'http://localhost/foo'
},
{
script_name => '/foo bar',
host => 'localhost',
base => 'http://localhost/foo%20bar'
},
{
scheme => 'http',
host => 'localhost:91',
base => 'http://localhost:91/'
},
{
scheme => 'http',
host => 'example.com',
base => 'http://example.com/'
},
{
scheme => 'https',
host => 'example.com',
base => 'https://example.com/'
},
{
scheme => 'http',
server_name => 'example.com',
server_port => 80,
base => 'http://example.com/'
},
{
scheme => 'http',
server_name => 'example.com',
server_port => 8080,
base => 'http://example.com:8080/'
},
{
host => 'foobar.com',
server_name => 'example.com',
server_port => 8080,
base => 'http://foobar.com/'
},
);
plan tests => 1 * @tests;
for my $block (@tests) {
my $env = {
'spore.url_scheme' => $block->{scheme} || 'http',
HTTP_HOST => $block->{host} || undef,
SERVER_NAME => $block->{server_name} || undef,
SERVER_PORT => $block->{server_port} || undef,
SCRIPT_NAME => $block->{script_name} || '',
};
my $req = Net::HTTP::Spore::Request->new($env);
is $req->base, $block->{base};
}
|