| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Perlbal::Test::WebServer; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 58 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 58 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 58 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 58 | ▶ | use Socket qw(MSG_NOSIGNAL IPPROTO_TCP TCP_NODELAY SOL_SOCKET); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 58 | ▶ | use Perlbal::Test; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 58 | ▶ | use Perlbal::Test::WebClient; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 58 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 58 | ▶ | use vars qw(@ISA @EXPORT); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 58 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 58 | @EXPORT = qw(start_webserver); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 58 | our @webserver_pids; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 58 | my $testpid; # of the test suite's main program, the one running the HTTP client | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 58 | ▶ | END { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | # ensure we kill off the webserver | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 58 | ▶ | kill 9, @webserver_pids if $testpid && $testpid == $$; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$testpid and $testpid == $$
MC/DC100%2/2
$testpid and $testpid == $$
$testpid
$testpid == $$
Truth table100%3/3
A and B
A= $testpidB= $testpid == $$
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 81 | ▶ | sub start_webserver { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_webserver: called CC=12 SCAR=27.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 81 | my $port = new_port(); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # dummy mode | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 81 | ▶ | if ($ENV{'TEST_PERLBAL_USE_EXISTING'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return $port; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 81 | $testpid = $$; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 81 | ▶ | if (my $child = fork) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | # i am parent, wait for child to startup | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 45 | push @webserver_pids, $child; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 45 | my $sock = wait_on_child($child, $port); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 45 | ▶ | die "Unable to spawn webserver on port $port\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | unless $sock; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 45 | print $sock "GET /reqdecr,status HTTP/1.0\r\n\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 45 | my $line = <$sock>; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 45 | ▶ | die "Didn't get 200 OK: " . (defined $line ? $line : "(undef)") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$line and $line =~ /200 OK/
MC/DC0%0/2
$line and $line =~ /200 OK/
$line
$line =~ /200 OK/
Truth table33%1/3
A and B
A= $lineB= $line =~ /200 OK/
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | unless $line && $line =~ /200 OK/; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 45 | return $port; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # i am child, start up | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 36 | ▶ | my $ssock = IO::Socket::INET->new(LocalPort => $port, ReuseAddr => 1, Listen => 3) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | or die "Unable to start socket: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 36 | ▶ | while (my $csock = $ssock->accept) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 83 | ▶ | exit 0 unless $csock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 83 | ▶ | fork and next; # parent starts waiting for next request | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 36 | ▶ | setsockopt($csock, IPPROTO_TCP, TCP_NODELAY, pack("l", 1)) or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 36 | serve_client($csock); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 36 | ▶ | sub serve_client { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_client: called CC=35 SCAR=36.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 36 | my $csock = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 36 | my $req_num = 0; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 36 | my $did_options = 0; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 36 | my @reqs; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | REQ: | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 36 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 70 | 166 | my $req = ''; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 166 | my $clen = undef; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 166 | ▶ | while (<$csock>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 748 | $req .= $_; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 748 | ▶ | if (/^content-length:\s*(\d+)/i) { $clen = $1; }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 748 | ▶ | last if ! $_ || /^\r?\n/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $_ or /^\r?\n/
MC/DC50%1/2
not $_ or /^\r?\n/
not $_
/^\r?\n/
Truth table66%2/3
not(A) or B
A= not $_B= /^\r?\n/
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 166 | ▶ | exit 0 unless $req; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # parse out things we want to have | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 160 | my @cmds; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 160 | my $httpver = 0; # 0 = 1.0, 1 = 1.1, undef = neither | |||||||||||||||||||||||||||||||||||||||||
| 82 | 160 | my $method; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 160 | ▶ | if ($req =~ m!^([A-Z]+) /?(\S+) HTTP/(1\.\d+)\r?\n?!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 159 | $method = $1; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 159 | my $cmds = durl($2); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 159 | @cmds = split(/\s*,\s*/, $cmds); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 159 | $req_num++; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 159 | ▶ | $httpver = ($3 eq '1.0' ? 0 : ($3 eq '1.1' ? 1 : undef)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 160 | my $msg = HTTP::Request->parse($req); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 160 | my $keeping_alive = undef; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 160 | my $body; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 160 | ▶ | if ($clen) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 85 | ▶ | die "Can't read a body on a GET or HEAD" if $method =~ /^GET|HEAD$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 85 | my $read = read $csock, $body, $clen; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 85 | ▶ | die "Didn't read $clen bytes. Got $read." if $clen != $read; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 160 | ▶ | my $response = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=17 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 160 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 160 | my $code = delete $opts{code}; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 160 | my $codetext = delete $opts{codetext}; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 160 | my $content = delete $opts{content}; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 160 | my $ctype = delete $opts{type}; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 160 | my $extra_hdr = delete $opts{headers}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 160 | ▶ | die "unknown data in opts: %opts" if %opts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 160 | ▶ | $extra_hdr ||= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$extra_hdr ||= ""
MC/DC100%1/1
$extra_hdr ||= ""
$extra_hdr
Truth table100%2/2
A
A= $extra_hdr
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 160 | ▶ | $code ||= $content ? 200 : 200; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$code ||= $content ? 200 : 200
MC/DC0%0/2
$code ||= $content ? 200 : 200
$code
$content ? 200 : 200
Truth table66%2/3
A ||= B
A= $codeB= $content ? 200 : 200
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 160 | ▶ | $codetext ||= { 200 => 'OK', 500 => 'Internal Server Error', 204 => "No Content" }->{$code}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$codetext ||= {200, "OK", 500, "Internal Server Error", 204, "No Content"}->{$code}
MC/DC0%0/2
$codetext ||= {200, "OK", 500, "Internal Server Error", 204, "No Content"}->{$code}
$codetext
{200, "OK", 500, "Internal Server Error", 204, "No Content"}->{$code}
Truth table33%1/3
A ||= B
A= $codetextB= {200, "OK", 500, "Internal Server Error", 204, "No Content"}->{$code}
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 160 | ▶ | $content ||= ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$content ||= ""
MC/DC100%1/1
$content ||= ""
$content
Truth table100%2/2
A
A= $content
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 160 | my $clen = length $content; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 160 | ▶ | $ctype ||= "text/plain" unless $code == 204; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ctype ||= "text/plain"
MC/DC0%0/1
$ctype ||= "text/plain"
$ctype
Truth table50%1/2
A
A= $ctype
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 160 | ▶ | $extra_hdr .= "Content-Type: $ctype\r\n" if $ctype; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 160 | my $hdr_keepalive = ""; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 160 | ▶ | unless (defined $keeping_alive) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 158 | ▶ | my $hdr_connection = $msg->header('Connection') || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$msg->header('Connection') || ''
MC/DC100%1/1
$msg->header('Connection') || ''
$msg->header('Connection')
Truth table100%2/2
A
A= $msg->header('Connection')
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 158 | ▶ | if ($httpver == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($hdr_connection =~ /\bclose\b/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $keeping_alive = 0; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $keeping_alive = "1.1implicit"; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 158 | ▶ | if ($httpver == 0 && $hdr_connection =~ /\bkeep-alive\b/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$httpver == 0 and $hdr_connection =~ /\bkeep-alive\b/i
MC/DC50%1/2
$httpver == 0 and $hdr_connection =~ /\bkeep-alive\b/i
$httpver == 0
$hdr_connection =~ /\bkeep-alive\b/i
Truth table66%2/3
A and B
A= $httpver == 0B= $hdr_connection =~ /\bkeep-alive\b/i
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 130 | $keeping_alive = "1.0keepalive"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 160 | ▶ | if ($keeping_alive) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 130 | $hdr_keepalive = "Connection: keep-alive\n"; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 30 | $hdr_keepalive = "Connection: close\n"; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 160 | return "HTTP/1.0 $code $codetext\r\n" . | |||||||||||||||||||||||||||||||||||||||||
| 141 | $hdr_keepalive . | ||||||||||||||||||||||||||||||||||||||||||
| 142 | "Content-Length: $clen\r\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 143 | $extra_hdr . | ||||||||||||||||||||||||||||||||||||||||||
| 144 | "\r\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 145 | "$content"; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 160 | }; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 160 | ▶ | my $send = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 160 | my $res = shift; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 160 | print $csock $res; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 160 | ▶ | exit 0 unless $keeping_alive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 160 | }; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | # 500 if no commands were given or we don't know their HTTP version | ||||||||||||||||||||||||||||||||||||||||||
| 155 | # or we didn't parse a proper HTTP request | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 160 | ▶ | unless (@cmds && defined $httpver && $msg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@cmds and defined $httpver and $msg
@cmds and defined $httpver
MC/DC33%1/3
@cmds and defined $httpver and $msg
@cmds
defined $httpver
$msg
Truth table50%2/4
A and B and C
A= @cmdsB= defined $httpverC= $msg
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | print STDERR "500 response!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | $send->($response->(code => 500)); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | next REQ; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 159 | ▶ | if ($method eq "OPTIONS") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | $did_options = 1; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | $send->($response->(code => 200)); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | next REQ; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | # prepare a simple 200 to send; undef this if you want to control | ||||||||||||||||||||||||||||||||||||||||||
| 169 | # your own output below | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 158 | my $to_send; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 158 | foreach my $cmd (@cmds) { | |||||||||||||||||||||||||||||||||||||||||
| 173 | 180 | $cmd =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 180 | $cmd =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 180 | ▶ | if ($cmd =~ /^sleep:([\d\.]+)$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | my $sleeptime = $1; | |||||||||||||||||||||||||||||||||||||||||
| 178 | #print "I, $$, should sleep for $sleeptime.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 58 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 4 | my $t1 = Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | select undef, undef, undef, $1; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | my $t2 = Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | my $td = $t2 - $t1; | |||||||||||||||||||||||||||||||||||||||||
| 184 | #print "I, $$, slept for $td\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 180 | ▶ | if ($cmd =~ /^keepalive:([01])$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | $keeping_alive = $1; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 180 | ▶ | if ($cmd eq "status") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 129 | ▶ | my $len = $clen || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$clen || 0
MC/DC100%1/1
$clen || 0
$clen
Truth table100%2/2
A
A= $clen
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 129 | ▶ | my $bu = $msg->header('X-PERLBAL-BUFFERED-UPLOAD-REASON') || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$msg->header('X-PERLBAL-BUFFERED-UPLOAD-REASON') || ''
MC/DC100%1/1
$msg->header('X-PERLBAL-BUFFERED-UPLOAD-REASON') || ''
$msg->header('X-PERLBAL-BUFFERED-UPLOAD-REASON')
Truth table100%2/2
A
A= $msg->header('X-PERLBAL-BUFFERED-UPLOAD-REASON')
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 129 | $to_send = $response->(content => | |||||||||||||||||||||||||||||||||||||||||
| 195 | "pid = $$\nreqnum = $req_num\nmethod = $method\n". | ||||||||||||||||||||||||||||||||||||||||||
| 196 | "length = $len\nbuffered = $bu\noptions = $did_options\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 180 | ▶ | if ($cmd eq "reqdecr") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 15 | $req_num--; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 180 | ▶ | if ($cmd =~ /^kill:(\d+):(\w+)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | kill $2, $1; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 180 | ▶ | if ($cmd =~ /^reproxy_url:(.+)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 12 | $to_send = $response->(headers => "X-Reproxy-URL: $1\r\n", | |||||||||||||||||||||||||||||||||||||||||
| 209 | code => 204, | ||||||||||||||||||||||||||||||||||||||||||
| 210 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 180 | ▶ | if ($cmd =~ /^reproxy_url204:(.+)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | $to_send = $response->(headers => "X-Reproxy-URL: $1\r\n"); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 180 | ▶ | if ($cmd =~ /^reproxy_url_cached:(\d+):(.+)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | kill 'USR1', $testpid; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | $to_send = $response->(headers => | |||||||||||||||||||||||||||||||||||||||||
| 220 | "X-Reproxy-URL: $2\r\nX-Reproxy-Cache-For: $1; Last-Modified Content-Type\r\nLast-Modified: 199\r\nContent-Type: application/badger\r\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 180 | ▶ | if ($cmd =~ /^reproxy_url_multi:((?:\d+:){2,})(\S+)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | my $ports = $1; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | my $path = $2; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | my @urls; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | foreach my $port (split(/:/, $ports)) { | |||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | push @urls, "http://127.0.0.1:$port$path"; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | $to_send = $response->(headers => "X-Reproxy-URL: @urls\r\n"); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 180 | ▶ | if ($cmd =~ /^reproxy_file:(.+)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 10 | $to_send = $response->(headers => "X-Reproxy-File: $1\r\n"); | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 180 | ▶ | if ($cmd =~ /^subreq:(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | my $port = $1; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | my $wc = Perlbal::Test::WebClient->new; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | $wc->server("127.0.0.1:$port"); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | $wc->keepalive(0); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | $wc->http_version('1.0'); | |||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | my $resp = $wc->request("status"); | |||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | my $subpid; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | ▶ | if ($resp && $resp->content =~ /^pid = (\d+)$/m) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$resp and $resp->content =~ /^pid = (\d+)$/m
MC/DC0%0/2
$resp and $resp->content =~ /^pid = (\d+)$/m
$resp
$resp->content =~ /^pid = (\d+)$/m
Truth table33%1/3
A and B
A= $respB= $resp->content =~ /^pid = (\d+)$/m
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | $subpid = $1; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | $to_send = $response->(content => "pid = $$\nsubpid = $subpid\nreqnum = $req_num\n"); | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 180 | ▶ | if ($cmd =~ /^reflect_request_headers$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | $to_send = $response->(content => $msg->headers->as_string); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 158 | ▶ | $send->($to_send || $response->()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$to_send || &$response()
MC/DC0%0/2
$to_send || &$response()
$to_send
&$response()
Truth table33%1/3
A || B
A= $to_sendB= &$response()
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | } # while(1) | ||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # de-url escape | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 159 | ▶ | sub durl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
durl: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 159 | my ($a) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 159 | $a =~ tr/+/ /; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $a =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 159 | return $a; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 58 | 1; | |||||||||||||||||||||||||||||||||||||||||