| 1 | package HTTP::Lite; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.005; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Socket 1.3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Errno qw(EAGAIN); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '2.44'; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my $BLOCKSIZE = 65536; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | my $CRLF = "\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $URLENCODE_VALID = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-."; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Forward declarations | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | sub prepare_post; | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | sub http_write; | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | sub http_readline; | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | sub http_read; | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub http_readbytes; | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # Prepare the urlencode validchars lookup hash | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my @urlencode_valid; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | foreach my $char (split('', $URLENCODE_VALID)) { | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 65 | $urlencode_valid[ord $char]=$char; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | for (my $n=0;$n<256;$n++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 256 | ▶ | if (!defined($urlencode_valid[$n])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 191 | $urlencode_valid[$n]=sprintf("%%%02X", $n); | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | bless $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | $self->initialize(); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | sub initialize | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | $self->reset; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $self->{timeout} = 120; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | $self->{HTTP11} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | $self->{DEBUG} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | $self->{header_at_once} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | $self->{holdback} = 0; # needed for http_write | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sub header_at_once | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_at_once: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $self->{header_at_once} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | sub local_addr | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
local_addr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $oldval = $self->{'local_addr'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (defined($val)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->{'local_addr'} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return $oldval; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | sub local_port | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
local_port: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $oldval = $self->{'local_port'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if (defined($val)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $self->{'local_port'} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return $oldval; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | sub method | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
method: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $method = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $method = uc($method); | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->{method} = $method; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | sub DEBUG | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEBUG: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($self->{DEBUG}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | print STDERR join(" ", @_),"\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | sub reset | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | foreach my $var ("body", "request", "content", "status", "proxy", | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | "proxyport", "resp-protocol", "error-message", | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | "resp-headers", "CBARGS", "callback_function", "callback_params") | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 12 | $self->{$var} = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | $self->{HTTPReadBuffer} = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $self->{method} = "GET"; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | $self->{headers} = { 'user-agent' => "HTTP::Lite/$VERSION" }; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | $self->{headermap} = { 'user-agent' => 'User-Agent' }; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # URL-encode data | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub escape { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
escape: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $toencode = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | return join('', | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | map { $urlencode_valid[ord $_] } split('', $toencode)); | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub set_callback { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_callback: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ($self, $callback, @callbackparams) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $self->{'callback_function'} = $callback; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->{'callback_params'} = [ @callbackparams ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | sub request | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: not called CC=66 SCAR=83.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my ($self, $url, $data_callback, $cbargs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $method = $self->{method}; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if (defined($cbargs)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->{CBARGS} = $cbargs; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $callback_func = $self->{'callback_function'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $callback_params = $self->{'callback_params'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # Parse URL | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my ($protocol,$host,$junk,$port,$object) = | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | $url =~ m{^([^:/]+)://([^/:]*)(:(\d+))?(/?.*)$}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Only HTTP is supported here | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($protocol ne "http") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | warn "Only http is supported by HTTP::Lite"; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Setup the connection | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $proto = getprotobyname('tcp'); | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | local *FH; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | socket(FH, PF_INET, SOCK_STREAM, $proto); | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $port = 80 if !$port; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $connecthost = $self->{'proxy'} || $host; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'proxy'} || $host
MC/DC0%0/2
$self->{'proxy'} || $host
$self->{'proxy'}
$host
Truth table0%0/3
A || B
A= $self->{'proxy'}B= $host
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $connecthost = $connecthost ? $connecthost : $host; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my $connectport = $self->{'proxyport'} || $port; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'proxyport'} || $port
MC/DC0%0/2
$self->{'proxyport'} || $port
$self->{'proxyport'}
$port
Truth table0%0/3
A || B
A= $self->{'proxyport'}B= $port
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $connectport = $connectport ? $connectport : $port; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $addr = inet_aton($connecthost); | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if (!$addr) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | close(FH); | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ($connecthost ne $host) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # if proxy active, use full URL as object to request | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $object = "$url"; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # choose local port and address | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my $local_addr = INADDR_ANY; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $local_port = "0"; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if (defined($self->{'local_addr'})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $local_addr = $self->{'local_addr'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($local_addr eq "0.0.0.0" || $local_addr eq "0") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$local_addr eq "0.0.0.0" or $local_addr eq 0
MC/DC0%0/2
$local_addr eq "0.0.0.0" or $local_addr eq 0
$local_addr eq "0.0.0.0"
$local_addr eq 0
Truth table0%0/3
A or B
A= $local_addr eq "0.0.0.0"B= $local_addr eq 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $local_addr = INADDR_ANY; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $local_addr = inet_aton($local_addr); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if (defined($self->{'local_port'})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $local_port = $self->{'local_port'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $paddr = pack_sockaddr_in($local_port, $local_addr); | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | bind(FH, $paddr) || return undef; # Failing to bind is fatal. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $sin = sockaddr_in($connectport,$addr); | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | connect(FH, $sin) || return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # Set nonblocking IO on the handle to allow timeouts | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if ( $^O ne "MSWin32" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | fcntl(FH, F_SETFL, O_NONBLOCK); | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if (defined($callback_func)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | &$callback_func($self, "connect", undef, @$callback_params); | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ($self->{header_at_once}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $self->{holdback} = 1; # http_write should buffer only, no sending yet | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Start the request (HTTP/1.1 mode) | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if ($self->{HTTP11}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $self->http_write(*FH, "$method $object HTTP/1.1$CRLF"); | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $self->http_write(*FH, "$method $object HTTP/1.0$CRLF"); | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # Add some required headers | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # we only support a single transaction per request in this version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->add_req_header("Connection", "close"); | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ($port != 80) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $self->add_req_header("Host", "$host:$port"); | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $self->add_req_header("Host", $host); | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if (!defined($self->get_req_header("Accept"))) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $self->add_req_header("Accept", "*/*"); | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ($method eq 'POST') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $self->http_write(*FH, "Content-Type: application/x-www-form-urlencoded$CRLF"); | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # Purge a couple others | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $self->delete_req_header("Content-Type"); | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self->delete_req_header("Content-Length"); | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # Output headers | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | foreach my $header ($self->enum_req_headers()) | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $value = $self->get_req_header($header); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $self->http_write(*FH, $self->{headermap}{$header}.": ".$value."$CRLF"); | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $content_length; | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (defined($self->{content})) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $content_length = length($self->{content}); | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if (defined($callback_func)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $ncontent_length = &$callback_func($self, "content-length", undef, @$callback_params); | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if (defined($ncontent_length)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $content_length = $ncontent_length; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if ($content_length) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $self->http_write(*FH, "Content-Length: $content_length$CRLF"); | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if (defined($callback_func)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | &$callback_func($self, "done-headers", undef, @$callback_params); | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # End of headers | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $self->http_write(*FH, "$CRLF"); | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if ($self->{header_at_once}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $self->{holdback} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $self->http_write(*FH, ""); # pseudocall to get http_write going | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my $content_out = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if (defined($callback_func)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | while (my $content = &$callback_func($self, "content", undef, @$callback_params)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $self->http_write(*FH, $content); | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $content_out++; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Output content, if any | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (!$content_out && defined($self->{content})) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $content_out and defined $self->{"content"}
MC/DC0%0/2
not $content_out and defined $self->{"content"}
not $content_out
defined $self->{"content"}
Truth table0%0/3
not(A) and B
A= not $content_outB= defined $self->{"content"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $self->http_write(*FH, $self->{content}); | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if (defined($callback_func)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | &$callback_func($self, "content-done", undef, @$callback_params); | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # Read response from server | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $headmode=1; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $chunkmode=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $chunksize=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $chunklength=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $chunk; | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $line = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | while ($data = $self->http_read(*FH,$headmode,$chunkmode,$chunksize)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | $self->{DEBUG} && $self->DEBUG("reading: $chunkmode, $chunksize, $chunklength, $headmode, ". | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | length($self->{'body'})); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ($self->{DEBUG}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | foreach my $var ("body", "request", "content", "status", "proxy", | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | "proxyport", "resp-protocol", "error-message", | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | "resp-headers", "CBARGS", "HTTPReadBuffer") | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $self->DEBUG("state $var ".length($self->{$var})); | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $line++; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ($line == 1) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my ($proto,$status,$message) = split(' ', $$data, 3); | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("header $$data"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $self->{status}=$status; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $self->{'resp-protocol'}=$proto; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $self->{'error-message'}=$message; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if (($headmode || $chunkmode eq "entity-header") && $$data =~ /^[\r\n]*$/) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$headmode || $chunkmode eq "entity-header" and $$data =~ /^[\r\n]*$/
$headmode or $chunkmode eq "entity-header"
MC/DC0%0/3
$headmode || $chunkmode eq "entity-header" and $$data =~ /^[\r\n]*$/
$headmode
$chunkmode eq "entity-header"
$$data =~ /^[\r\n]*$/
Truth table0%0/5
A or B and C
A= $headmodeB= $chunkmode eq "entity-header"C= $$data =~ /^[\r\n]*$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if ($chunkmode) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $chunkmode = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $headmode = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # Check for Transfer-Encoding | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $te = $self->get_header("Transfer-Encoding"); | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if (defined($te)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $header = join(' ',@{$te}); | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if ($header =~ /chunked/i) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $chunkmode = "chunksize"; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ($headmode || $chunkmode eq "entity-header") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$headmode or $chunkmode eq "entity-header"
MC/DC0%0/2
$headmode or $chunkmode eq "entity-header"
$headmode
$chunkmode eq "entity-header"
Truth table0%0/3
A or B
A= $headmodeB= $chunkmode eq "entity-header"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my ($var,$datastr) = $$data =~ /^([^:]*):\s*(.*)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if (defined($var)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $datastr =~s/[\r\n]$//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $var = lc($var); | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $var =~ s/^(.)/&upper($1)/ge; | |||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $var =~ s/(-.)/&upper($1)/ge; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $hr = ${$self->{'resp-headers'}}{$var}; | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if (!ref($hr)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $hr = [ $datastr ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | push @{ $hr }, $datastr; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ${$self->{'resp-headers'}}{$var} = $hr; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } elsif ($chunkmode) | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ($chunkmode eq "chunksize") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $chunksize = $$data; | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $chunksize =~ s/^\s*|;.*$//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $chunksize =~ s/\s*$//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $cshx = $chunksize; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if (length($chunksize) > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # read another line | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ($chunksize !~ /^[a-f0-9]+$/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("chunksize not a hex string"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $chunksize = hex($chunksize); | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("chunksize was $chunksize (HEX was $cshx)"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if ($chunksize == 0) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $chunkmode = "entity-header"; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $chunkmode = "chunk"; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $chunklength = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("chunksize empty string, checking next line!"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } elsif ($chunkmode eq "chunk") | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $chunk .= $$data; | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $chunklength += length($$data); | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if ($chunklength >= $chunksize) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $chunkmode = "chunksize"; | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if ($chunklength > $chunksize) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $chunk = substr($chunk,0,$chunksize); | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | ▶ | elsif ($chunklength == $chunksize && $chunk !~ /$CRLF$/) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$chunklength == $chunksize and not $chunk =~ /$CRLF$/
MC/DC0%0/2
$chunklength == $chunksize and not $chunk =~ /$CRLF$/
$chunklength == $chunksize
not $chunk =~ /$CRLF$/
Truth table0%0/3
A and not(B)
A= $chunklength == $chunksizeB= not $chunk =~ /$CRLF$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # chunk data is exactly chunksize -- need CRLF still | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $chunkmode = "ignorecrlf"; | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | $self->add_to_body(\$chunk, $data_callback); | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $chunk=""; | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $chunklength = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $chunksize = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } elsif ($chunkmode eq "ignorecrlf") | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $chunkmode = "chunksize"; | |||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $self->add_to_body($data, $data_callback); | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if (defined($callback_func)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | &$callback_func($self, "done", undef, @$callback_params); | |||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | close(FH); | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | return $self->{status}; | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | sub add_to_body | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_to_body: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | my ($dataref, $data_callback) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my $callback_func = $self->{'callback_function'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $callback_params = $self->{'callback_params'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if (!defined($data_callback) && !defined($callback_func)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $data_callback || defined $callback_func
MC/DC0%0/2
defined $data_callback || defined $callback_func
defined $data_callback
defined $callback_func
Truth table0%0/3
A || B
A= defined $data_callbackB= defined $callback_func
| |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("no callback"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $self->{'body'}.=$$dataref; | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my $newdata; | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | if (defined($callback_func)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $newdata = &$callback_func($self, "data", $dataref, @$callback_params); | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $newdata = &$data_callback($self, $dataref, $self->{CBARGS}); | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if ($self->{DEBUG}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $self->DEBUG("callback got back a ".ref($newdata)); | |||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if (ref($newdata) eq "SCALAR") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $self->DEBUG("callback got back ".length($$newdata)." bytes"); | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if (defined($newdata) && ref($newdata) eq "SCALAR") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $newdata and ref $newdata eq "SCALAR"
MC/DC0%0/2
defined $newdata and ref $newdata eq "SCALAR"
defined $newdata
ref $newdata eq "SCALAR"
Truth table0%0/3
A and B
A= defined $newdataB= ref $newdata eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $self->{'body'} .= $$newdata; | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | sub add_req_header | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_req_header: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my ($header, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | return unless defined($value); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my $lcheader = lc($header); | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("add_req_header $header $value"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ${$self->{headers}}{$lcheader} = $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ${$self->{headermap}}{$lcheader} = $header; | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | sub get_req_header | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_req_header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my ($header) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | return $self->{headers}{lc($header)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | sub delete_req_header | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_req_header: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my ($header) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | my $exists; | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if ($exists=defined(${$self->{headers}}{lc($header)})) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | delete ${$self->{headers}}{lc($header)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | delete ${$self->{headermap}}{lc($header)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return $exists; | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | sub enum_req_headers | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enum_req_headers: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | my ($header) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my $exists; | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | return keys %{$self->{headermap}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | sub body | ||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | return $self->{'body'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | sub status | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | return $self->{status}; | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | sub protocol | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
protocol: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | return $self->{'resp-protocol'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | sub status_message | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_message: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return $self->{'error-message'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | sub proxy | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proxy: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # Parse URL | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | my ($protocol,$host,$junk,$port,$object) = | |||||||||||||||||||||||||||||||||||||||||||||
| 516 | $value =~ m{^(\S+)://([^/:]*)(:(\d+))?(/.*)$}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | if (!$host) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ($host,$port) = $value =~ /^([^:]+):(.*)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | $self->{'proxy'} = $host || $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$host || $value
MC/DC0%0/2
$host || $value
$host
$value
Truth table0%0/3
A || B
A= $hostB= $value
| |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | $self->{'proxyport'} = $port || 80; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$port || 80
MC/DC0%0/1
$port || 80
$port
Truth table0%0/2
A
A= $port
| |||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | sub headers_array | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers_array: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my @array = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | foreach my $header (keys %{$self->{'resp-headers'}}) | |||||||||||||||||||||||||||||||||||||||||||||
| 533 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my $aref = ${$self->{'resp-headers'}}{$header}; | |||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | foreach my $value (@$aref) | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | push @array, "$header: $value"; | |||||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | return @array; | |||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | sub headers_string | ||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers_string: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my $string = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | foreach my $header (keys %{$self->{'resp-headers'}}) | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | my $aref = ${$self->{'resp-headers'}}{$header}; | |||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | foreach my $value (@$aref) | |||||||||||||||||||||||||||||||||||||||||||||
| 553 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | $string .= "$header: $value\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | sub get_header | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | my $header = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | return $self->{'resp-headers'}{$header}; | |||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||
| 568 | sub http11_mode | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http11_mode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1 | my $mode = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | $self->{HTTP11} = $mode; | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||
| 576 | sub prepare_post | ||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_post: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | my $varref = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | my $body = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | ▶ | while (my ($var,$value) = map { escape($_) } each %$varref) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 583 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | if ($body) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 585 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | $body .= "&$var=$value"; | |||||||||||||||||||||||||||||||||||||||||||||
| 587 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | $body = "$var=$value"; | |||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $self->{content} = $body; | |||||||||||||||||||||||||||||||||||||||||||||
| 592 | $self->{headers}{'Content-Type'} = "application/x-www-form-urlencoded" | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | unless defined ($self->{headers}{'Content-Type'}) and | ||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | ▶ | $self->{headers}{'Content-Type'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"headers"}{"Content-Type"} and $self->{"headers"}{"Content-Type"}
MC/DC0%0/2
defined $self->{"headers"}{"Content-Type"} and $self->{"headers"}{"Content-Type"}
defined $self->{"headers"}{"Content-Type"}
$self->{"headers"}{"Content-Type"}
Truth table0%0/3
A and B
A= defined $self->{"headers"}{"Content-Type"}B= $self->{"headers"}{"Content-Type"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | $self->{method} = "POST"; | |||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||
| 598 | sub http_write | ||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_write: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my ($fh,$line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | if ($self->{holdback}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | $self->{HTTPWriteBuffer} .= $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 606 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | if (defined $self->{HTTPWriteBuffer}) { # copy previously buffered, if any | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | $line = $self->{HTTPWriteBuffer} . $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | my $size = length($line); | |||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | my $total_sent = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | my $nbytes; | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $nbytes = syswrite($fh, $line, $size - $total_sent, $total_sent ); | |||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | die $! unless(defined($nbytes) || $!{EAGAIN}); # non-recoverable error occurred! | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $nbytes or $!{"EAGAIN"}
MC/DC0%0/2
defined $nbytes or $!{"EAGAIN"}
defined $nbytes
$!{"EAGAIN"}
Truth table0%0/3
A or B
A= defined $nbytesB= $!{"EAGAIN"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | $total_sent += $nbytes; | |||||||||||||||||||||||||||||||||||||||||||||
| 619 | } while ($total_sent < $size); | ||||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||
| 622 | sub http_read | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_read: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | my ($fh,$headmode,$chunkmode,$chunksize) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("read handle=$fh, headm=$headmode, chunkm=$chunkmode, chunksize=$chunksize"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | if (($headmode == 0 && $chunkmode eq "0") || ($chunkmode eq "chunk")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$headmode == 0 and $chunkmode eq 0 or $chunkmode eq "chunk"
$headmode == 0 and $chunkmode eq 0
MC/DC0%0/3
$headmode == 0 and $chunkmode eq 0 or $chunkmode eq "chunk"
$headmode == 0
$chunkmode eq 0
$chunkmode eq "chunk"
Truth table0%0/5
A and B or C
A= $headmode == 0B= $chunkmode eq 0C= $chunkmode eq "chunk"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | my $bytes_to_read = $chunkmode eq "chunk" ? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 632 | ($chunksize < $BLOCKSIZE ? $chunksize : $BLOCKSIZE) : | ||||||||||||||||||||||||||||||||||||||||||||||
| 633 | $BLOCKSIZE; | ||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $res = $self->http_readbytes($fh,$self->{timeout},$bytes_to_read); | |||||||||||||||||||||||||||||||||||||||||||||
| 635 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | $res = $self->http_readline($fh,$self->{timeout}); | |||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | if ($res) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | if ($self->{DEBUG}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | $self->DEBUG("read got ".length($$res)." bytes"); | |||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | my $str = $$res; | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | $str =~ s{([\x00-\x1F\x7F-\xFF])}{.}g; | |||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | $self->DEBUG("read: ".$str); | |||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||
| 649 | sub http_readline | ||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_readline: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | my ($fh, $timeout) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | my $EOL = "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("readline handle=$fh, timeout=$timeout"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||
| 657 | # is there a line in the buffer yet? | ||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | ▶ | while ($self->{HTTPReadBuffer} !~ /$EOL/) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 659 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 660 | # nope -- wait for incoming data | ||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | my ($inbuf,$bits,$chars) = ("","",0); | |||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | vec($bits,fileno($fh),1)=1; | |||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | my $nfound = select($bits, undef, $bits, $timeout); | |||||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | ▶ | if ($nfound == 0) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 665 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 666 | # Timed out | ||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 668 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # Get the data | ||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | $chars = sysread($fh, $inbuf, $BLOCKSIZE); | |||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("sysread $chars bytes"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # End of stream? | ||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | if ($chars <= 0 && !$!{EAGAIN}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$chars <= 0 and not $!{"EAGAIN"}
MC/DC0%0/2
$chars <= 0 and not $!{"EAGAIN"}
$chars <= 0
not $!{"EAGAIN"}
Truth table0%0/3
A and not(B)
A= $chars <= 0B= not $!{"EAGAIN"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 675 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # tag data onto end of buffer | ||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | $self->{HTTPReadBuffer}.=$inbuf; | |||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # get a single line from the buffer | ||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | my $nlat = index($self->{HTTPReadBuffer}, $EOL); | |||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | my $newline; | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | my $oldline; | ||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | if ($nlat > -1) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 686 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | $newline = substr($self->{HTTPReadBuffer},0,$nlat+1); | |||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | $oldline = substr($self->{HTTPReadBuffer},$nlat+1); | |||||||||||||||||||||||||||||||||||||||||||||
| 689 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | $newline = substr($self->{HTTPReadBuffer},0); | |||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | $oldline = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # and update the buffer | ||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | $self->{HTTPReadBuffer}=$oldline; | |||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | return length($newline) ? \$newline : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||
| 698 | sub http_readbytes | ||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_readbytes: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | my ($fh, $timeout, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | my $EOL = "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("readbytes handle=$fh, timeout=$timeout, bytes=$bytes"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # is there enough data in the buffer yet? | ||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | while (length($self->{HTTPReadBuffer}) < $bytes) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 708 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # nope -- wait for incoming data | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | my ($inbuf,$bits,$chars) = ("","",0); | |||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | vec($bits,fileno($fh),1)=1; | |||||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | my $nfound = select($bits, undef, $bits, $timeout); | |||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | ▶ | if ($nfound == 0) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # Timed out | ||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 717 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # Get the data | ||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | $chars = sysread($fh, $inbuf, $BLOCKSIZE); | |||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | ▶ | $self->{DEBUG} && $self->DEBUG("sysread $chars bytes"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 722 | # End of stream? | ||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | ▶ | if ($chars <= 0 && !$!{EAGAIN}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$chars <= 0 and not $!{"EAGAIN"}
MC/DC0%0/2
$chars <= 0 and not $!{"EAGAIN"}
$chars <= 0
not $!{"EAGAIN"}
Truth table0%0/3
A and not(B)
A= $chars <= 0B= not $!{"EAGAIN"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 724 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # tag data onto end of buffer | ||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | $self->{HTTPReadBuffer}.=$inbuf; | |||||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | my $newline; | |||||||||||||||||||||||||||||||||||||||||||||
| 731 | my $buflen; | ||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | if (($buflen=length($self->{HTTPReadBuffer})) >= $bytes) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 733 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | $newline = substr($self->{HTTPReadBuffer},0,$bytes+1); | |||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if ($bytes+1 < $buflen) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | $self->{HTTPReadBuffer} = substr($self->{HTTPReadBuffer},$bytes+1); | |||||||||||||||||||||||||||||||||||||||||||||
| 737 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | $self->{HTTPReadBuffer} = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 740 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | $newline = substr($self->{HTTPReadBuffer},0); | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | $self->{HTTPReadBuffer} = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | ▶ | return length($newline) ? \$newline : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||
| 747 | sub upper | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upper: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | my ($str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | if (defined($str)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | return uc($str); | |||||||||||||||||||||||||||||||||||||||||||||
| 752 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||||||
| 759 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||