5 use Perlbal
::Test
::WebServer
;
6 use Perlbal
::Test
::WebClient
;
7 use Test
::More tests
=> 35;
9 my ($back_port) = start_webserver
();
11 # setup a simple perlbal that uses the above server
12 my $webport = new_port
();
14 my $deadport = new_port
();
15 my $pb_port = new_port
();
21 SET test
.role
= reverse_proxy
22 SET test
.listen = 127.0.0.1:$pb_port
23 SET test
.persist_client
= 1
24 SET test
.persist_backend
= 1
26 SET test
.connect_ahead
= 0
27 SET test
.enable_reproxy
= true
31 SET ws
.role
= web_server
32 SET ws
.listen = 127.0.0.1:$webport
34 SET ws
.dirindexing
= 0
35 SET ws
.persist_client
= 1
40 my $msock = start_server
($conf);
41 ok
($msock, 'perlbal started');
42 ok
(manage
("POOL a ADD 127.0.0.1:$back_port"), "backend port added");
44 my $wc = Perlbal
::Test
::WebClient
->new;
45 $wc->server("127.0.0.1:$pb_port");
47 $wc->http_version('1.0');
49 # see if a single request works
50 my $resp = $wc->request('status');
51 ok
($resp, 'status response ok');
54 # make a file on disk, verifying we can get it via disk/URL
55 my $phrase = "foo bar yo this is my content.\n";
56 my $file_content = $phrase x
1000;
57 open(F
, ">$dir/foo.txt");
58 print F
$file_content;
60 ok
(filecontent
("$dir/foo.txt") eq $file_content, "file good via disk");
62 my $hc = Perlbal
::Test
::WebClient
->new;
63 $hc->server("127.0.0.1:$webport");
65 $hc->http_version('1.0');
66 $resp = $hc->request('foo.txt');
67 ok
($resp && $resp->content eq $file_content, 'file good via network');
70 # now request some ranges on it.....
72 foreach my $meth (qw(http rp_file rp_url)) {
80 'rp_file' => "reproxy_file:$dir/foo.txt",
81 'rp_url' => "reproxy_url:http://127.0.0.1:$webport/foo.txt",
88 $resp = $ua->request({ headers
=> "Range: $range\r\n"}, $path);
92 if ($meth eq "rp_file" || $meth eq "http") {
93 @aios = qw(none ioaio);
96 foreach my $aio (@aios) {
97 my $setaio = $aio eq "-" ?
1 : manage
("SERVER aio_mode = $aio");
99 skip
"can't do AIO mode $aio", 6 unless $setaio;
101 $send->("bytes=0-6");
102 ok
($resp && $resp->content eq "foo bar", "$meth/$aio: range $range");
103 ok
($resp->status_line =~ /^206/, "is partial") or diag
(dump_res
($resp));
105 $send->("bytes=" . length($phrase) . "-");
106 ok
($resp && $resp->content eq ($phrase x
999), "$meth/$aio: range $range");
107 ok
($resp->status_line =~ /^206/, "is partial") or diag
(dump_res
($resp));
109 $send->("bytes=" . length($file_content) . "-");
110 ok
($resp && $resp->status_line =~ /^416/, "$meth/$aio: can't satisify") or diag
(dump_res
($resp));
112 $send->("bytes=5-1");
113 ok
($resp && $resp->status_line =~ /^416/, "$meth/$aio: can't satisify") or diag
(dump_res
($resp));
120 # try to reproxy to a list of URLs, where the first one is bogus, and last one is good
121 #ok_reproxy_url_list();
123 sub ok_reproxy_url_list
{
124 my $resp = $wc->request("reproxy_url_multi:$deadport:$webport:/foo.txt");
125 ok
($resp->content eq $file_content, "reproxy URL w/ dead one first");
128 sub ok_reproxy_file
{
129 my $resp = $wc->request("reproxy_file:$dir/foo.txt");
130 ok
($resp && $resp->content eq $file_content, "reproxy file");
134 my $resp = $wc->request("reproxy_url:http://127.0.0.1:$webport/foo.txt");
135 ok
($resp->content eq $file_content, "reproxy URL");
139 my $resp = $wc->request('status');
140 ok
($resp && $resp->content =~ /\bpid\b/, 'status ok');