| 1 | package Net::HTTP::Methods; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | our $VERSION = '6.22'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | my $CRLF = "\015\012"; # "\r\n" is not portable | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | *_bytes = defined(&utf8::downgrade) ? | ||||||||||||||||||||||||||||||||||||||||||
| 10 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 18 | ▶ | unless (utf8::downgrade($_[0], 1)) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | Carp::croak("Wide character in HTTP request (bytes required)"); | |||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 18 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | : | ||||||||||||||||||||||||||||||||||||||||||
| 18 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | return $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | unshift(@_, "Host") if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | my %cnf = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | require Symbol; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | my $self = bless Symbol::gensym(), $class; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | return $self->http_configure(\%cnf); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | sub http_configure { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | ▶ | my($self, $cnf) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_configure: called CC=20 SCAR=30.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | ▶ | die "Listen option not allowed" if $cnf->{Listen}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | my $explicit_host = (exists $cnf->{Host}); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | my $host = delete $cnf->{Host}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | # All this because $cnf->{PeerAddr} = 0 is actually valid. | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | my $peer; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | for my $key (qw{PeerAddr PeerHost}) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 12 | ▶ | next if !defined($cnf->{$key}) || q{} eq $cnf->{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $cnf->{$key} or "" eq $cnf->{$key}
MC/DC50%1/2
not defined $cnf->{$key} or "" eq $cnf->{$key}
not defined $cnf->{$key}
"" eq $cnf->{$key}
Truth table66%2/3
not(A) or B
A= not defined $cnf->{$key}B= "" eq $cnf->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | $peer = $cnf->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | ▶ | if (!defined $peer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | die "No Host option provided" unless $host; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | $cnf->{PeerAddr} = $peer = $host; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # CONNECTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # PREFER: port number from PeerAddr, then PeerPort, then http_default_port | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | my $peer_uri = URI->new("http://$peer"); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | $cnf->{"PeerPort"} = $peer_uri->_port || $cnf->{PeerPort} || $self->http_default_port; | ||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$peer_uri->_port || $cnf->{'PeerPort'} || $self->http_default_port
$peer_uri->_port or $cnf->{"PeerPort"}
MC/DC0%0/3
$peer_uri->_port || $cnf->{'PeerPort'} || $self->http_default_port
$peer_uri->_port
$cnf->{"PeerPort"}
$self->http_default_port
Truth table75%3/4
A or B || C
A= $peer_uri->_portB= $cnf->{"PeerPort"}C= $self->http_default_port
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | $cnf->{"PeerAddr"} = $peer_uri->host; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # HOST header: | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # If specified but blank, ignore. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # If specified with a value, add the port number | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # If not specified, set to PeerAddr and port number | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # ALWAYS: If IPv6 address, use [brackets] (thanks to the URI package) | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # ALWAYS: omit port number if http_default_port | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | ▶ | if (($host) || (! $explicit_host)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$host or not $explicit_host
MC/DC100%2/2
$host or not $explicit_host
$host
not $explicit_host
Truth table100%3/3
A or not(B)
A= $hostB= not $explicit_host
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | ▶ | my $uri = ($explicit_host) ? URI->new("http://$host") : $peer_uri->clone; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | ▶ | if (!$uri->_port) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Always use *our* $self->http_default_port instead of URI's (Covers HTTP, HTTPS) | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | ▶ | $uri->port( $cnf->{PeerPort} || $self->http_default_port); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$cnf->{'PeerPort'} || $self->http_default_port
MC/DC0%0/2
$cnf->{'PeerPort'} || $self->http_default_port
$cnf->{'PeerPort'}
$self->http_default_port
Truth table33%1/3
A || B
A= $cnf->{'PeerPort'}B= $self->http_default_port
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | my $host_port = $uri->host_port; # Returns host:port or [ipv6]:port | |||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | my $remove = ":" . $self->http_default_port; # we want to remove the default port number | |||||||||||||||||||||||||||||||||||||||||
| 70 | 6 | ▶ | if (substr($host_port,0-length($remove)) eq $remove) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | substr($host_port,0-length($remove)) = ""; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | $host = $host_port; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | $cnf->{Proto} = 'tcp'; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 7 | my $keep_alive = delete $cnf->{KeepAlive}; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | my $http_version = delete $cnf->{HTTPVersion}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | ▶ | $http_version = "1.1" unless defined $http_version; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | my $peer_http_version = delete $cnf->{PeerHTTPVersion}; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | ▶ | $peer_http_version = "1.0" unless defined $peer_http_version; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | my $send_te = delete $cnf->{SendTE}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | my $max_line_length = delete $cnf->{MaxLineLength}; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | ▶ | $max_line_length = 8*1024 unless defined $max_line_length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | my $max_header_lines = delete $cnf->{MaxHeaderLines}; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | ▶ | $max_header_lines = 128 unless defined $max_header_lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 7 | ▶ | return undef unless $self->http_connect($cnf); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 6 | $self->host($host); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | $self->keep_alive($keep_alive); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | $self->send_te($send_te); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | $self->http_version($http_version); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | $self->peer_http_version($peer_http_version); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | $self->max_line_length($max_line_length); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | $self->max_header_lines($max_header_lines); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 6 | ${*$self}{'http_buf'} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | sub http_default_port { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 9 | ▶ | 80; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_default_port: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # set up property accessors | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | for my $method (qw(host keep_alive send_te max_line_length max_header_lines peer_http_version)) { | |||||||||||||||||||||||||||||||||||||||||
| 110 | 24 | my $prop_name = "http_" . $method; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | *$method = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 75 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 75 | my $old = ${*$self}{$prop_name}; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 75 | ▶ | ${*$self}{$prop_name} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 75 | return $old; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 24 | }; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # we want this one to be a bit smarter | ||||||||||||||||||||||||||||||||||||||||||
| 121 | sub http_version { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_version: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | my $old = ${*$self}{'http_version'}; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | my $v = shift; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 7 | ▶ | $v = "1.0" if $v eq "1"; # float | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 7 | ▶ | unless ($v eq "1.0" or $v eq "1.1") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$v eq "1.0" or $v eq "1.1"
MC/DC0%0/2
$v eq "1.0" or $v eq "1.1"
$v eq "1.0"
$v eq "1.1"
Truth table66%2/3
A or B
A= $v eq "1.0"B= $v eq "1.1"
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | Carp::croak("Unsupported HTTP version '$v'"); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | ${*$self}{'http_version'} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 7 | $old; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | sub format_request { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 18 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_request: called CC=22 SCAR=35.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 18 | my $method = shift; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 18 | my $uri = shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 18 | ▶ | my $content = (@_ % 2) ? pop : ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 18 | for ($method, $uri) { | |||||||||||||||||||||||||||||||||||||||||
| 144 | 36 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 36 | ▶ | Carp::croak("Bad method or uri") if /\s/ || !length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
/\s/ or not length $_
MC/DC0%0/2
/\s/ or not length $_
/\s/
not length $_
Truth table33%1/3
A or not(B)
A= /\s/B= not length $_
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 18 | push(@{${*$self}{'http_request_method'}}, $method); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 18 | my $ver = ${*$self}{'http_version'}; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 18 | ▶ | my $peer_ver = ${*$self}{'http_peer_http_version'} || "1.0"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
do {
*$self
}->{'http_peer_http_version'} || '1.0'
MC/DC0%0/1
do {
*$self
}->{'http_peer_http_version'} || '1.0'
do {
*$self
}->{'http_peer_http_version'}
Truth table50%1/2
A
A= do {
*$self
}->{'http_peer_http_version'}
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 18 | my @h; | |||||||||||||||||||||||||||||||||||||||||
| 153 | my @connection; | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 18 | my %given = (host => 0, "content-length" => 0, "te" => 0); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 18 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 6 | my($k, $v) = splice(@_, 0, 2); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | my $lc_k = lc($k); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | ▶ | if ($lc_k eq "connection") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $v =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $v =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | push(@connection, split(/\s*,\s*/, $v)); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | ▶ | if (exists $given{$lc_k}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $given{$lc_k}++; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 6 | push(@h, "$k: $v"); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 18 | ▶ | if (length($content) && !$given{'content-length'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $content and not $given{"content-length"}
MC/DC0%0/2
length $content and not $given{"content-length"}
length $content
not $given{"content-length"}
Truth table33%1/3
A and not(B)
A= length $contentB= not $given{"content-length"}
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | push(@h, "Content-Length: " . length($content)); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 18 | my @h2; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 18 | ▶ | if ($given{te}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | push(@connection, "TE") unless grep lc($_) eq "te", @connection; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | ▶ | elsif ($self->send_te && gunzip_ok()) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->send_te and gunzip_ok()
MC/DC0%0/2
$self->send_te and gunzip_ok()
$self->send_te
gunzip_ok()
Truth table33%1/3
A and B
A= $self->send_teB= gunzip_ok()
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | # gzip is less wanted since the IO::Uncompress::Gunzip interface for | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # it does not really allow chunked decoding to take place easily. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | push(@h2, "TE: deflate,gzip;q=0.3"); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | push(@connection, "TE"); | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 18 | ▶ | unless (grep lc($_) eq "close", @connection) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 18 | ▶ | if ($self->keep_alive) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 10 | ▶ | if ($peer_ver eq "1.0") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | # from looking at Netscape's headers | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 4 | push(@h2, "Keep-Alive: 300"); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 4 | unshift(@connection, "Keep-Alive"); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 8 | ▶ | push(@connection, "close") if $ver ge "1.1"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 18 | ▶ | push(@h2, "Connection: " . join(", ", @connection)) if @connection; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 18 | ▶ | unless ($given{host}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 18 | my $h = ${*$self}{'http_host'}; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 18 | ▶ | push(@h2, "Host: $h") if $h; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 18 | return _bytes(join($CRLF, "$method $uri HTTP/$ver", @h2, @h, "", $content)); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | sub write_request { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 18 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_request: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 18 | $self->print($self->format_request(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | sub format_chunk { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_chunk: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return $_[0] unless defined($_[0]) && length($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_[0] and length $_[0]
MC/DC0%0/2
defined $_[0] and length $_[0]
defined $_[0]
length $_[0]
Truth table0%0/3
A and B
A= defined $_[0]B= length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return _bytes(sprintf("%x", length($_[0])) . $CRLF . $_[0] . $CRLF); | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | sub write_chunk { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_chunk: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | return 1 unless defined($_[0]) && length($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_[0] and length $_[0]
MC/DC0%0/2
defined $_[0] and length $_[0]
defined $_[0]
length $_[0]
Truth table0%0/3
A and B
A= defined $_[0]B= length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->print(_bytes(sprintf("%x", length($_[0])) . $CRLF . $_[0] . $CRLF)); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | sub format_chunk_eof { | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_chunk_eof: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my @h; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | push(@h, sprintf "%s: %s$CRLF", splice(@_, 0, 2)); | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return _bytes(join("", "0$CRLF", @h, $CRLF)); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | sub write_chunk_eof { | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_chunk_eof: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $self->print($self->format_chunk_eof(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | sub my_read { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 916 | ▶ | die if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
my_read: called CC=5 SCAR=16.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 916 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 916 | my $len = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 916 | for (${*$self}{'http_buf'}) { | |||||||||||||||||||||||||||||||||||||||||
| 244 | 916 | ▶ | if (length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 10 | $_[0] = substr($_, 0, $len, ""); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 10 | return length($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 906 | ▶ | die "read timeout" unless $self->can_read; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 906 | return $self->sysread($_[0], $len); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | sub my_readline { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 125 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
my_readline: called CC=17 SCAR=35.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 125 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 125 | for (${*$self}{'http_buf'}) { | |||||||||||||||||||||||||||||||||||||||||
| 260 | 125 | my $max_line_length = ${*$self}{'http_max_line_length'}; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 125 | my $pos; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 125 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 263 | # find line ending | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 604 | $pos = index($_, "\012"); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 604 | ▶ | last if $pos >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 479 | ▶ | die "$what line too long (limit is $max_line_length)" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$max_line_length and length $_ > $max_line_length
MC/DC0%0/2
$max_line_length and length $_ > $max_line_length
$max_line_length
length $_ > $max_line_length
Truth table33%1/3
A and B
A= $max_line_lengthB= length $_ > $max_line_length
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | if $max_line_length && length($_) > $max_line_length; | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | # need to read more data to find a line ending | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 479 | my $new_bytes = 0; | |||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | READ: | ||||||||||||||||||||||||||||||||||||||||||
| 273 | { # wait until bytes start arriving | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 479 | ▶ | $self->can_read | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | or die "read timeout"; | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | # consume all incoming bytes | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 479 | my $bytes_read = $self->sysread($_, 1024, length); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 479 | ▶ | if(defined $bytes_read) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 479 | $new_bytes += $bytes_read; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | elsif($!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK}) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Condition0%0/6
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EINTR"} or $!{"EAGAIN"}
MC/DC0%0/3
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EINTR"}
$!{"EAGAIN"}
$!{"EWOULDBLOCK"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EAGAIN"}C= $!{"EWOULDBLOCK"}
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | redo READ; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # if we have already accumulated some data let's at | ||||||||||||||||||||||||||||||||||||||||||
| 287 | # least return that as a line | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | length or die "$what read failed: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | # no line-ending, no new bytes | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 479 | ▶ | return length($_) ? substr($_, 0, length($_), "") : undef | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | if $new_bytes==0; | ||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 125 | ▶ | die "$what line too long ($pos; limit is $max_line_length)" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$max_line_length and $pos > $max_line_length
MC/DC0%0/2
$max_line_length and $pos > $max_line_length
$max_line_length
$pos > $max_line_length
Truth table33%1/3
A and B
A= $max_line_lengthB= $pos > $max_line_length
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | if $max_line_length && $pos > $max_line_length; | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 125 | my $line = substr($_, 0, $pos+1, ""); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 125 | ▶ | $line =~ s/(\015?\012)\z// || die "Assert"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 125 | ▶ | return wantarray ? ($line, $1) : $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | sub can_read { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 1382 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_read: called CC=16 SCAR=39.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 1382 | ▶ | return 1 unless defined(fileno($self)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 882 | ▶ | return 1 if $self->isa('IO::Socket::SSL') && $self->pending; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->isa("IO::Socket::SSL") and $self->pending
MC/DC50%1/2
$self->isa("IO::Socket::SSL") and $self->pending
$self->isa("IO::Socket::SSL")
$self->pending
Truth table66%2/3
A and B
A= $self->isa("IO::Socket::SSL")B= $self->pending
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 16 | ▶ | return 1 if $self->isa('Net::SSL') && $self->can('pending') && $self->pending; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->isa("Net::SSL") and $self->can("pending") and $self->pending
$self->isa("Net::SSL") and $self->can("pending")
MC/DC0%0/3
$self->isa("Net::SSL") and $self->can("pending") and $self->pending
$self->isa("Net::SSL")
$self->can("pending")
$self->pending
Truth table25%1/4
A and B and C
A= $self->isa("Net::SSL")B= $self->can("pending")C= $self->pending
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | # With no timeout, wait forever. An explicit timeout of 0 can be | ||||||||||||||||||||||||||||||||||||||||||
| 313 | # used to just check if the socket is readable without waiting. | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 16 | ▶ | my $timeout = @_ ? shift : (${*$self}{io_socket_timeout} || undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
do {
*$self
}->{"io_socket_timeout"} or undef
MC/DC0%0/1
do {
*$self
}->{"io_socket_timeout"} or undef
do {
*$self
}->{"io_socket_timeout"}
Truth table50%1/2
A
A= do {
*$self
}->{"io_socket_timeout"}
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 16 | my $fbits = ''; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 16 | vec($fbits, fileno($self), 1) = 1; | |||||||||||||||||||||||||||||||||||||||||
| 318 | SELECT: | ||||||||||||||||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 16 | my $before; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 16 | ▶ | $before = time if $timeout; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 16 | my $nfound = select($fbits, undef, undef, $timeout); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 16 | ▶ | if ($nfound < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if ($!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EINTR"} or $!{"EAGAIN"}
MC/DC0%0/3
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EINTR"}
$!{"EAGAIN"}
$!{"EWOULDBLOCK"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EAGAIN"}C= $!{"EWOULDBLOCK"}
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | # don't really think EAGAIN/EWOULDBLOCK can happen here | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if ($timeout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $timeout -= time - $before; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | $timeout = 0 if $timeout < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | redo SELECT; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | die "select failed: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 16 | return $nfound > 0; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | sub _rbuf { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rbuf: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | for (${*$self}{'http_buf'}) { | |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $old; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | $old = $_ if defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $_ = shift; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | return $old; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return ${*$self}{'http_buf'}; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | sub _rbuf_length { | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rbuf_length: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | return length ${*$self}{'http_buf'}; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | sub _read_header_lines { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_header_lines: called CC=8 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 19 | my $junk_out = shift; | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 19 | my @headers; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 19 | my $line_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 19 | my $max_header_lines = ${*$self}{'http_max_header_lines'}; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 19 | ▶ | while (my $line = my_readline($self, 'Header')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 68 | ▶ | if ($line =~ /^(\S+?)\s*:\s*(.*)/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 66 | push(@headers, $1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | ▶ | elsif (@headers && $line =~ s/^\s+//) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
@headers and $line =~ s/^\s+//
MC/DC0%0/2
@headers and $line =~ s/^\s+//
@headers
$line =~ s/^\s+//
Truth table33%1/3
A and B
A= @headersB= $line =~ s/^\s+//
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $headers[-1] .= " " . $line; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | elsif ($junk_out) { | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | push(@$junk_out, $line); | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | die "Bad header: '$line'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 67 | ▶ | if ($max_header_lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 67 | $line_count++; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 67 | ▶ | if ($line_count >= $max_header_lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | die "Too many header lines (limit is $max_header_lines)"; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 18 | return @headers; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | sub read_response_headers { | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 18 | ▶ | my($self, %opt) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_response_headers: called CC=16 SCAR=28.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 18 | my $laxed = $opt{laxed}; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 18 | my($status, $eol) = my_readline($self, 'Status'); | |||||||||||||||||||||||||||||||||||||||||
| 396 | 18 | ▶ | unless (defined $status) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | die "Server closed connection without sending any data back"; | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 18 | my($peer_ver, $code, $message) = split(/\s+/, $status, 3); | |||||||||||||||||||||||||||||||||||||||||
| 401 | 18 | ▶ | if (!$peer_ver || $peer_ver !~ s,^HTTP/,, || $code !~ /^[1-5]\d\d$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$peer_ver and $peer_ver =~ s[^HTTP/][] and $code =~ /^[1-5]\d\d$/
$peer_ver and $peer_ver =~ s[^HTTP/][]
MC/DC33%1/3
$peer_ver and $peer_ver =~ s[^HTTP/][] and $code =~ /^[1-5]\d\d$/
$peer_ver
$peer_ver =~ s[^HTTP/][]
$code =~ /^[1-5]\d\d$/
Truth table50%2/4
A and B and C
A= $peer_verB= $peer_ver =~ s[^HTTP/][]C= $code =~ /^[1-5]\d\d$/
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 2 | ▶ | die "Bad response status line: '$status'" unless $laxed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | # assume HTTP/0.9 | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | ${*$self}{'http_peer_http_version'} = "0.9"; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | ${*$self}{'http_status'} = "200"; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | ▶ | substr(${*$self}{'http_buf'}, 0, 0) = $status . ($eol || ""); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$eol || ''
MC/DC0%0/1
$eol || ''
$eol
Truth table50%1/2
A
A= $eol
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | return 200 unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | return (200, "Assumed OK"); | |||||||||||||||||||||||||||||||||||||||||
| 409 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 16 | ${*$self}{'http_peer_http_version'} = $peer_ver; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 16 | ${*$self}{'http_status'} = $code; | |||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 16 | my $junk_out; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 16 | ▶ | if ($laxed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | $junk_out = $opt{junk_out} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{'junk_out'} || []
MC/DC0%0/1
$opt{'junk_out'} || []
$opt{'junk_out'}
Truth table50%1/2
A
A= $opt{'junk_out'}
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 16 | my @headers = $self->_read_header_lines($junk_out); | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | # pick out headers that read_entity_body might need | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 15 | my @te; | |||||||||||||||||||||||||||||||||||||||||
| 422 | my $content_length; | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 15 | ▶ | for (my $i = 0; $i < @headers; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 62 | my $h = lc($headers[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 425 | 62 | ▶ | if ($h eq 'transfer-encoding') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | my $te = $headers[$i+1]; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 4 | $te =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 4 | $te =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 4 | ▶ | push(@te, $te) if length($te); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | elsif ($h eq 'content-length') { | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # ignore bogus and overflow values | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 10 | ▶ | if ($headers[$i+1] =~ /^\s*(\d{1,15})(?:\s|$)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 10 | $content_length = $1; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 15 | ${*$self}{'http_te'} = join(",", @te); | |||||||||||||||||||||||||||||||||||||||||
| 439 | 15 | ${*$self}{'http_content_length'} = $content_length; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 15 | ${*$self}{'http_first_body'}++; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 15 | delete ${*$self}{'http_trailers'}; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 15 | ▶ | return $code unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 15 | return ($code, $message, @headers); | |||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | sub read_entity_body { | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 929 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_entity_body: called CC=41 SCAR=46.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 929 | my $buf_ref = \$_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 929 | my $size = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 929 | ▶ | die "Offset not supported yet" if $_[2]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 929 | my $chunked; | |||||||||||||||||||||||||||||||||||||||||
| 454 | my $bytes; | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 929 | ▶ | if (${*$self}{'http_first_body'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 15 | ${*$self}{'http_first_body'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 15 | delete ${*$self}{'http_chunked'}; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 15 | delete ${*$self}{'http_bytes'}; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 15 | my $method = shift(@{${*$self}{'http_request_method'}}); | |||||||||||||||||||||||||||||||||||||||||
| 461 | 15 | my $status = ${*$self}{'http_status'}; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 15 | ▶ | if ($method eq "HEAD") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | # this response is always empty regardless of other headers | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 1 | $bytes = 0; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 14 | elsif (my $te = ${*$self}{'http_te'}) { | |||||||||||||||||||||||||||||||||||||||||
| 467 | 3 | my @te = split(/\s*,\s*/, lc($te)); | |||||||||||||||||||||||||||||||||||||||||
| 468 | 3 | ▶ | die "Chunked must be last Transfer-Encoding '$te'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | unless pop(@te) eq "chunked"; | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 3 | ▶ | pop(@te) while @te && $te[-1] eq "chunked"; # ignore repeated chunked spec | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@te and $te[-1] eq "chunked"
MC/DC50%1/2
@te and $te[-1] eq "chunked"
@te
$te[-1] eq "chunked"
Truth table66%2/3
A and B
A= @teB= $te[-1] eq "chunked"
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 3 | for (@te) { | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if ($_ eq "deflate" && inflate_ok()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$_ eq "deflate" and inflate_ok()
MC/DC0%0/2
$_ eq "deflate" and inflate_ok()
$_ eq "deflate"
inflate_ok()
Truth table0%0/3
A and B
A= $_ eq "deflate"B= inflate_ok()
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | #require Compress::Raw::Zlib; | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my ($i, $status) = Compress::Raw::Zlib::Inflate->new(); | |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | die "Can't make inflator: $status" unless $i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | $_ = sub { my $out; $i->inflate($_[0], \$out); $out } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 479 | ▶ | elsif ($_ eq "gzip" && gunzip_ok()) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ eq "gzip" and gunzip_ok()
MC/DC0%0/2
$_ eq "gzip" and gunzip_ok()
$_ eq "gzip"
gunzip_ok()
Truth table0%0/3
A and B
A= $_ eq "gzip"B= gunzip_ok()
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | #require IO::Uncompress::Gunzip; | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my @buf; | |||||||||||||||||||||||||||||||||||||||||
| 482 | $_ = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | push(@buf, $_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | return "" unless $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | my $input = join("", @buf); | |||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | my $output; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | IO::Uncompress::Gunzip::gunzip(\$input, \$output, Transparent => 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | or die "Can't gunzip content: $IO::Uncompress::Gunzip::GunzipError"; | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | return \$output; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | elsif ($_ eq "identity") { | ||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | $_ = sub { $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | die "Can't handle transfer encoding '$te'"; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 3 | @te = reverse(@te); | |||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 3 | ▶ | ${*$self}{'http_te2'} = @te ? \@te : ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 3 | $chunked = -1; | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 11 | elsif (defined(my $content_length = ${*$self}{'http_content_length'})) { | |||||||||||||||||||||||||||||||||||||||||
| 506 | 9 | $bytes = $content_length; | |||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | elsif ($status =~ /^(?:1|[23]04)/) { | ||||||||||||||||||||||||||||||||||||||||||
| 509 | # RFC 2616 says that these responses should always be empty | ||||||||||||||||||||||||||||||||||||||||||
| 510 | # but that does not appear to be true in practice [RT#17907] | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | $bytes = 0; | |||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # XXX Multi-Part types are self delimiting, but RFC 2616 says we | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # only has to deal with 'multipart/byteranges' | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | # Read until EOF | ||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 914 | $chunked = ${*$self}{'http_chunked'}; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 914 | $bytes = ${*$self}{'http_bytes'}; | |||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 929 | ▶ | if (defined $chunked) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | # The state encoded in $chunked is: | ||||||||||||||||||||||||||||||||||||||||||
| 527 | # $chunked == 0: read CRLF after chunk, then chunk header | ||||||||||||||||||||||||||||||||||||||||||
| 528 | # $chunked == -1: read chunk header | ||||||||||||||||||||||||||||||||||||||||||
| 529 | # $chunked > 0: bytes left in current chunk to read | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | 18 | ▶ | if ($chunked <= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 12 | my $line = my_readline($self, 'Entity body'); | |||||||||||||||||||||||||||||||||||||||||
| 533 | 12 | ▶ | if ($chunked == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 9 | ▶ | die "Missing newline after chunk data: '$line'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $line or $line ne ""
MC/DC0%0/2
not defined $line or $line ne ""
not defined $line
$line ne ""
Truth table33%1/3
not(A) or B
A= not defined $lineB= $line ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | if !defined($line) || $line ne ""; | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 9 | $line = my_readline($self, 'Entity body'); | |||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 12 | ▶ | die "EOF when chunk header expected" unless defined($line); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 12 | my $chunk_len = $line; | |||||||||||||||||||||||||||||||||||||||||
| 540 | 12 | $chunk_len =~ s/;.*//; # ignore potential chunk parameters | |||||||||||||||||||||||||||||||||||||||||
| 541 | 12 | ▶ | unless ($chunk_len =~ /^([\da-fA-F]+)\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | die "Bad chunk-size in HTTP response: $line"; | |||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 12 | $chunked = hex($1); | |||||||||||||||||||||||||||||||||||||||||
| 545 | 12 | ${*$self}{'http_chunked'} = $chunked; | |||||||||||||||||||||||||||||||||||||||||
| 546 | 12 | ▶ | if ($chunked == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 3 | ${*$self}{'http_trailers'} = [$self->_read_header_lines]; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 3 | $$buf_ref = ""; | |||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | 3 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||
| 551 | 3 | ▶ | if (my $transforms = delete ${*$self}{'http_te2'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | for (@$transforms) { | |||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | $$buf_ref = &$_($$buf_ref, 1); | |||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | $n = length($$buf_ref); | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | # in case somebody tries to read more, make sure we continue | ||||||||||||||||||||||||||||||||||||||||||
| 559 | # to return EOF | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 3 | delete ${*$self}{'http_chunked'}; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 3 | ${*$self}{'http_bytes'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 3 | return $n; | |||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 15 | my $n = $chunked; | |||||||||||||||||||||||||||||||||||||||||
| 568 | 15 | ▶ | $n = $size if $size && $size < $n; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$size and $size < $n
MC/DC0%0/2
$size and $size < $n
$size
$size < $n
Truth table33%1/3
A and B
A= $sizeB= $size < $n
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | 15 | $n = my_read($self, $$buf_ref, $n); | |||||||||||||||||||||||||||||||||||||||||
| 570 | 15 | ▶ | return undef unless defined $n; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | 15 | ${*$self}{'http_chunked'} = $chunked - $n; | |||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | 15 | ▶ | if ($n > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 15 | ▶ | if (my $transforms = ${*$self}{'http_te2'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | for (@$transforms) { | |||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $$buf_ref = &$_($$buf_ref, 0); | |||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $n = length($$buf_ref); | |||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | $n = -1 if $n == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 15 | return $n; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | elsif (defined $bytes) { | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 906 | ▶ | unless ($bytes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 10 | $$buf_ref = ""; | |||||||||||||||||||||||||||||||||||||||||
| 588 | 10 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 896 | my $n = $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 896 | ▶ | $n = $size if $size && $size < $n; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$size and $size < $n
MC/DC50%1/2
$size and $size < $n
$size
$size < $n
Truth table66%2/3
A and B
A= $sizeB= $size < $n
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 896 | $n = my_read($self, $$buf_ref, $n); | |||||||||||||||||||||||||||||||||||||||||
| 593 | 896 | ▶ | ${*$self}{'http_bytes'} = defined $n ? $bytes - $n : $bytes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 896 | return $n; | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 597 | # read until eof | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 5 | ▶ | $size ||= 8*1024; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$size ||= 8192
MC/DC0%0/1
$size ||= 8192
$size
Truth table50%1/2
A
A= $size
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 5 | return my_read($self, $$buf_ref, $size); | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | sub get_trailers { | ||||||||||||||||||||||||||||||||||||||||||
| 604 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_trailers: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 13 | ▶ | @{${*$self}{'http_trailers'} || []}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 609 | 4 | ▶ | my $gunzip_ok; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 4 | my $inflate_ok; | |||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||
| 612 | sub gunzip_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | return $gunzip_ok if defined $gunzip_ok; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gunzip_ok: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | # Try to load IO::Uncompress::Gunzip. | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | $gunzip_ok = 0; | |||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | require IO::Uncompress::Gunzip; | |||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | $gunzip_ok++; | |||||||||||||||||||||||||||||||||||||||||
| 623 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | return $gunzip_ok; | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | sub inflate_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | return $inflate_ok if defined $inflate_ok; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inflate_ok: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | # Try to load Compress::Raw::Zlib. | ||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $inflate_ok = 0; | |||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | require Compress::Raw::Zlib; | |||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | $inflate_ok++; | |||||||||||||||||||||||||||||||||||||||||
| 639 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | return $inflate_ok; | |||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | } # BEGIN | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||
| 648 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | Net::HTTP::Methods - Methods shared by Net::HTTP and Net::HTTPS | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | version 6.22 | ||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | Gisle Aas <gisle@activestate.com> | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | This software is copyright (c) 2001 by Gisle Aas. | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 669 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | __END__ | ||||||||||||||||||||||||||||||||||||||||||