SDK/Core/Transport/Default.pm

filter: Statementstmt 95.8% 93 / 97 Branchbran 71.6% 43 / 60 Conditioncond 54.7% 23 / 42 MC/DCmcdc 26.9% 7 / 26 Subroutinesub 100% 16 / 16 Podpod 100% 2 / 2 totaltotal 75.7% 184 / 243 CC 47 SCAR 22.7
CC
47
Cov
80%
send
15.9
wire_host
12.7
_is_backend_max_size_response
12.7
CRAP 9.7
« SDK/Storage/Tables.pm ↑ Summary SDK/Storage/Tables/Filter.pm »
1 15 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 15 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 15 ▶use Azure::SDK::Core::Transport;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Azure::SDK::Core::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Azure::SDK::Core::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 class Azure::SDK::Core::Transport::Default
10 15 :isa(Azure::SDK::Core::Transport) {
11 15 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶ use HTTP::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶ use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 15 field $agent :param :reader = undef;
16 15 field $timeout :param = 60;
17 15 field $max_response_bytes :param :reader = 64 * 1024 * 1024;
18
19 19 ▶ ADJUST {
Subroutine __ANON__: called CC=7 SCAR=22.1
20 19 ▶ croak 'max_response_bytes must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_response_bytes and $max_response_bytes =~ /\A\d+\z/u 0 19 19
Condition33%1/3
defined $max_response_bytes and $max_response_bytes =~ /\A\d+\z/u
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $max_response_bytes and $max_response_bytes =~ /\A\d+\z/u
defined $max_response_bytes $max_response_bytes =~ /\A\d+\z/u
Truth table33%1/3
A and B
A= defined $max_response_bytesB= $max_response_bytes =~ /\A\d+\z/u
ABresult
0X0
100
111
21 unless defined $max_response_bytes && $max_response_bytes =~ /\A\d+\z/;
22
23 19 ▶ $agent //= HTTP::Tiny->new(
Condition60%3/5
$agent //= "HTTP::Tiny"->new("timeout", $timeout, "max_size", $max_response_bytes || undef, "verify_SSL", 1)
l!l&&r!l&&!r
1360
$max_response_bytes || undef
l!l
60
MC/DC0%0/2
$agent //= "HTTP::Tiny"->new("timeout", $timeout, "max_size", $max_response_bytes || undef, "verify_SSL", 1)
$agent "HTTP::Tiny"->new("timeout", $timeout, "max_size", $max_response_bytes || undef, "verify_SSL", 1)
MC/DC0%0/1
$max_response_bytes || undef
$max_response_bytes
Truth table66%2/3
A //= B
A= $agentB= "HTTP::Tiny"->new("timeout", $timeout, "max_size", $max_response_bytes || undef, "verify_SSL", 1)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $max_response_bytes
Aresult
11
00
24 timeout => $timeout,
25 max_size => $max_response_bytes || undef,
26 verify_SSL => 1,
27 );
28
29 19 ▶ $agent->max_size($max_response_bytes || undef)
Branch: 1 branch
BranchTrueFalseTotal
if $agent->can("max_size") 12 7 19
Condition50%1/2
$max_response_bytes || undef
l!l
120
MC/DC0%0/1
$max_response_bytes || undef
$max_response_bytes
Truth table50%1/2
A
A= $max_response_bytes
Aresult
11
00
30 if $agent->can('max_size');
31 }
32
33 13 ▶ method send ($request) {
Subroutine send: called CC=15 SCAR=27.7
Pod documented
34 13 my $headers = $request->headers;
35 13 ▶ if (exists $headers->{host}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $headers->{"host"}) 8 5 13
36 8 my $wire_host = wire_host($request->url);
37 8 ▶ croak 'Host header requires an absolute HTTP(S) request URL'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wire_host 0 8 8
38 unless defined $wire_host;
39 croak 'Host header must match the canonical request URL authority'
40 8 ▶ unless $headers->{host} eq $wire_host;
Branch: 1 branch
BranchTrueFalseTotal
unless $headers->{"host"} eq $wire_host 1 7 8
41 7 delete $headers->{host};
42 }
43
44 12 my $body = '';
45 12 my $limit_error;
46 12 my $callback_called = 0;
47 12 my $checked_content_length = 0;
48
49 12 ▶ my %options = (
Branch: 1 branch
BranchTrueFalseTotal
defined $request->body ? : 7 5 12
50 headers => $headers,
51 ( defined $request->body ? ( content => $request->body ) : () ),
52 );
53
54 12 ▶ if ($max_response_bytes > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_response_bytes > 0) 12 0 12
55 6 ▶ $options{data_callback} = sub ($chunk, $partial_response) {
Subroutine __ANON__: called CC=5 SCAR=16.1
56 6 $callback_called = 1;
57
58 6 ▶ if (!$checked_content_length++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($checked_content_length++) 3 3 6
59 3 my $content_length = _content_length($partial_response->{headers});
60 3 ▶ if (defined $content_length && $content_length > $max_response_bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content_length and $content_length > $max_response_bytes) 1 2 3
Condition100%3/3
defined $content_length and $content_length > $max_response_bytes
!ll&&!rl&&r
111
MC/DC100%2/2
defined $content_length and $content_length > $max_response_bytes
defined $content_length $content_length > $max_response_bytes
Truth table100%3/3
A and B
A= defined $content_lengthB= $content_length > $max_response_bytes
ABresult
0X0
100
111
61 $limit_error = _response_too_large_error(
62 max => $max_response_bytes,
63 content_length => $content_length,
64 status => $partial_response->{status},
65 1 );
66 1 die $limit_error->to_string . "\n";
67 }
68 }
69
70 5 my $seen = bytes::length($body) + bytes::length($chunk);
71 5 ▶ if ($seen > $max_response_bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen > $max_response_bytes) 1 4 5
72 $limit_error = _response_too_large_error(
73 max => $max_response_bytes,
74 seen => $seen,
75 status => $partial_response->{status},
76 1 );
77 1 die $limit_error->to_string . "\n";
78 }
79
80 4 $body .= $chunk;
81 12 };
82 }
83
84 12 my $response = eval {
85 12 $agent->request(
86 $request->method,
87 $request->url,
88 \%options,
89 );
90 };
91 12 my $request_error = $@;
92
93 12 ▶ $limit_error->throw if defined $limit_error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit_error 2 10 12
94 10 ▶ die $request_error if $request_error;
Branch: 1 branch
BranchTrueFalseTotal
if $request_error 0 10 10
95
96 10 ▶ if (_is_backend_max_size_response($response, $max_response_bytes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_backend_max_size_response($response, $max_response_bytes)) 0 10 10
97 0 _response_too_large_error(max => $max_response_bytes)->throw;
98 }
99
100 10 ▶ if ($max_response_bytes > 0 && $response->{status} =~ /^2/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_response_bytes > 0 and $response->{'status'} =~ /^2/u) { } 10 0 10
Condition33%1/3
$max_response_bytes > 0 and $response->{"status"} =~ /^2/u
!ll&&!rl&&r
0010
MC/DC0%0/2
$max_response_bytes > 0 and $response->{"status"} =~ /^2/u
$max_response_bytes > 0 $response->{"status"} =~ /^2/u
Truth table33%1/3
A and B
A= $max_response_bytes > 0B= $response->{"status"} =~ /^2/u
ABresult
0X0
100
111
101 10 ▶ if (!$callback_called) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($callback_called) 9 1 10
102 9 ▶ $body = $response->{content} // '';
Condition50%1/2
$response->{"content"} // ""
l!l
90
MC/DC0%0/1
$response->{"content"} // ""
$response->{"content"}
Truth table50%1/2
A
A= $response->{"content"}
Aresult
11
00
103 9 my $seen = bytes::length($body);
104 _response_too_large_error(
105 max => $max_response_bytes,
106 seen => $seen,
107 status => $response->{status},
108 9 ▶ )->throw if $seen > $max_response_bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $seen > $max_response_bytes 0 9 9
109 }
110 }
111 else {
112 0 $body = $response->{content};
113 }
114
115 return Azure::SDK::Core::Response->new(
116 status => $response->{status},
117 headers => $response->{headers} // {},
118 10 ▶ body => $body,
Condition50%1/2
$response->{"headers"} // {}
l!l
100
MC/DC0%0/1
$response->{"headers"} // {}
$response->{"headers"}
Truth table50%1/2
A
A= $response->{"headers"}
Aresult
11
00
119 );
120 }
121
122 3 ▶ sub _content_length ($headers) {
Subroutine _content_length: called CC=6 SCAR=18.7
123 3 ▶ return undef unless ref $headers eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $headers eq "HASH" 0 3 3
124 3 ▶ my $value = $headers->{'content-length'} // $headers->{'Content-Length'};
Condition66%2/3
$headers->{"content-length"} // $headers->{"Content-Length"}
l!l&&r!l&&!r
201
MC/DC50%1/2
$headers->{"content-length"} // $headers->{"Content-Length"}
$headers->{"content-length"} $headers->{"Content-Length"}
Truth table66%2/3
A // B
A= $headers->{"content-length"}B= $headers->{"Content-Length"}
ABresult
1X1
011
000
125 3 ▶ $value = $value->[0] if ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 3 3
126 3 ▶ return undef unless defined $value && $value =~ /\A\s*(\d+)\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /\A\s*(\d+)\s*\z/u 1 2 3
Condition66%2/3
defined $value and $value =~ /\A\s*(\d+)\s*\z/u
!ll&&!rl&&r
102
MC/DC50%1/2
defined $value and $value =~ /\A\s*(\d+)\s*\z/u
defined $value $value =~ /\A\s*(\d+)\s*\z/u
Truth table66%2/3
A and B
A= defined $valueB= $value =~ /\A\s*(\d+)\s*\z/u
ABresult
0X0
100
111
127 2 return $1 + 0;
128 }
129
130 10 ▶ sub _is_backend_max_size_response ($response, $max) {
Subroutine _is_backend_max_size_response: called CC=6 SCAR=25.4
131 10 ▶ return 0 unless $max > 0 && ref $response eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $max > 0 and ref $response eq "HASH" 0 10 10
Condition33%1/3
$max > 0 and ref $response eq "HASH"
!ll&&!rl&&r
0010
MC/DC0%0/2
$max > 0 and ref $response eq "HASH"
$max > 0 ref $response eq "HASH"
Truth table33%1/3
A and B
A= $max > 0B= ref $response eq "HASH"
ABresult
0X0
100
111
132 10 ▶ return 0 unless ($response->{status} // 0) == 599;
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->{"status"} // 0) == 599 10 0 10
Condition50%1/2
$response->{"status"} // 0
l!l
100
MC/DC0%0/1
$response->{"status"} // 0
$response->{"status"}
Truth table50%1/2
A
A= $response->{"status"}
Aresult
11
00
133 0 ▶ return ($response->{content} // '') =~ /\ASize of response body exceeds the maximum allowed of \Q$max\E\s*\z/;
Condition0%0/2
$response->{"content"} // ""
l!l
00
MC/DC0%0/1
$response->{"content"} // ""
$response->{"content"}
Truth table0%0/2
A
A= $response->{"content"}
Aresult
11
00
134 }
135
136 2 ▶ sub _response_too_large_error (%args) {
Subroutine _response_too_large_error: called CC=3 SCAR=11.2
137 2 my $max = $args{max};
138 2 my $message;
139
140 2 ▶ if (defined $args{content_length}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'content_length'}) { } 1 1 2
elsif (defined $args{'seen'}) { } 1 0 1
141 1 $message = "Response Content-Length of $args{content_length} bytes exceeds "
142 . "configured max_response_bytes of $max bytes. Increase "
143 . "ClientOptions max_response_bytes if this response is expected.";
144 }
145 elsif (defined $args{seen}) {
146 1 $message = "Response body exceeded configured max_response_bytes of $max bytes "
147 . "after receiving $args{seen} bytes. Increase ClientOptions "
148 . "max_response_bytes if this response is expected.";
149 }
150 else {
151 0 $message = "Response body exceeded configured max_response_bytes of $max bytes. "
152 . "Increase ClientOptions max_response_bytes if this response is expected.";
153 }
154
155 return Azure::SDK::Core::Error->new(
156 message => $message,
157 status => $args{status},
158 2 code => 'ResponseTooLarge',
159 );
160 }
161
162 # Mirrors HTTP::Tiny's own Host derivation rather than URI->canonical,
163 # whose port normalization varies between URI releases (5.40 strips
164 # leading zeros, HTTP::Tiny sends the literal port digits).
165 17 ▶ sub wire_host ($url) {
Subroutine wire_host: called CC=11 SCAR=25.4
Pod documented
166 17 ▶ return undef unless defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 0 17 17
167 17 ▶ my ($scheme, $authority) = $url =~ m{\A([^:/?#]+)://([^/?#]*)}
Branch: 1 branch
BranchTrueFalseTotal
() = $url =~ m[\A([^:/?#]+)://([^/?#]*)]u or return undef 17 0 17
168 or return undef;
169 17 $scheme = lc $scheme;
170 17 ▶ return undef unless $scheme eq 'http' || $scheme eq 'https';
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme eq "http" or $scheme eq "https" 0 17 17
Condition33%1/3
$scheme eq "http" or $scheme eq "https"
l!l&&r!l&&!r
0170
MC/DC0%0/2
$scheme eq "http" or $scheme eq "https"
$scheme eq "http" $scheme eq "https"
Truth table33%1/3
A or B
A= $scheme eq "http"B= $scheme eq "https"
ABresult
1X1
011
000
171
172 17 $authority =~ s/\A[^@]*@//;
173 17 ▶ my $port = $authority =~ s/:(\d*)\z// && length $1 ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$authority =~ s/:(\d*)\z//u && length $1 ? : 10 7 17
Condition66%2/3
$authority =~ s/:(\d*)\z//u and length $1
!ll&&!rl&&r
7010
MC/DC50%1/2
$authority =~ s/:(\d*)\z//u and length $1
$authority =~ s/:(\d*)\z//u length $1
Truth table66%2/3
A and B
A= $authority =~ s/:(\d*)\z//uB= length $1
ABresult
0X0
100
111
174 17 ▶ return undef unless length $authority;
Branch: 1 branch
BranchTrueFalseTotal
unless length $authority 0 17 17
175
176 17 my $host = lc $authority;
177 17 ▶ my $default_port = $scheme eq 'https' ? 443 : 80;
Branch: 1 branch
BranchTrueFalseTotal
$scheme eq 'https' ? : 17 0 17
178 17 ▶ return defined $port && $port != $default_port ? "$host:$port" : $host;
Branch: 1 branch
BranchTrueFalseTotal
defined $port && $port != $default_port ? : 4 13 17
Condition100%3/3
defined $port and $port != $default_port
!ll&&!rl&&r
764
MC/DC100%2/2
defined $port and $port != $default_port
defined $port $port != $default_port
Truth table100%3/3
A and B
A= defined $portB= $port != $default_port
ABresult
0X0
100
111
179 }
180 }
181
182 15 1;
183
184 __END__
« SDK/Storage/Tables.pm ↑ Summary SDK/Storage/Tables/Filter.pm »