blib/lib/AnyEvent/MCP/Client/HTTP.pm

filter: Statementstmt 96.0% 96 / 100 Branchbran 77.1% 54 / 70 Conditioncond 65.4% 55 / 84 MC/DCmcdc 36.9% 17 / 46 Subroutinesub 92.8% 13 / 14 Podpod 100% 1 / 1 totaltotal 74.9% 236 / 315 CC 65 SCAR 27.5
CC
65
Cov
81%
_send
24.4
__ANON__
23.9
__ANON__
9.9
CRAP 15.6
« blib/lib/AnyEvent/MCP/Server/HTTP.pm ↑ Summary blib/lib/AnyEvent/MCP/Client.pm »
1 =head1 NAME
2  
3 AnyEvent::MCP::Client::HTTP - MCP over AnyEvent::HTTP
4  
5 =head1 SYNOPSIS
6  
7 use AnyEvent::MCP::Client::HTTP;
8  
9 my $client = AnyEvent::MCP::Client::HTTP->new (
10 name => "example", url => $url, bearer => $token,
11 timeout => 30,
12 );
13  
14 =head1 DESCRIPTION
15  
16 Use this transport to talk to an MCP server through HTTP. The caller supplies
17 the endpoint and, if needed, credentials; the common Client layer handles
18 discovery and tool calls. Unlike a browser, this client does not follow
19 redirects or silently retry requests. A redirected request could disclose
20 credentials to another host, and retrying a tool call could perform an
21 operation twice.
22  
23 =head1 FIRST CALL
24  
25 For a bundled MCP server already listening on HTTP, use the full URL
26 it prints with C<--print-url>:
27  
28 use AnyEvent;
29 use AnyEvent::MCP::Client::HTTP;
30  
31 my $client = AnyEvent::MCP::Client::HTTP->new (
32 url => "http://127.0.0.1:31740/TOKEN/",
33 );
34 my $cv = AE::cv;
35 $client->call (workdirs => {}, sub { $cv->send (@_) });
36 my ($success, $result) = $cv->recv;
37 $success or die "$result->{message}\n";
38 !$result->{isError} or die "$result->{content}[0]{text}\n";
39  
40 Replace the example URL with the actual credential-bearing URL. The
41 common L<AnyEvent::MCP::Client> layer negotiates MCP and handles
42 callbacks. A successful JSON-RPC exchange can still return a tool error
43 as C<isError>; always inspect both.
44  
45 =head1 METHODS
46  
47 =over
48  
49 =item $client = AnyEvent::MCP::Client::HTTP->new (%config)
50  
51 Accepts the common L<AnyEvent::MCP::Client> options and these transport
52 options. Options are flat, rather than nested in an HTTP configuration hash.
53  
54 =over
55  
56 =item url => $url
57  
58 Complete endpoint URL, optionally including a URL-path token. Required
59 unless supplied by the named client configuration.
60  
61 =item bearer => $token
62  
63 Supplies C<Authorization: Bearer TOKEN>. Without it, the URL alone is
64 used; a bearer token is not inferred from a URL. The server must accept
65 the selected credential. With the bundled servers, the URL-path token
66 and bearer header present the same static credential.
67  
68 =item name => $name
69  
70 Loads C<url>, C<bearer> and C<timeout> defaults from C<[client NAME]>.
71 Explicit constructor arguments override them, including explicitly undefined
72 credentials. Without a name no global configuration is accessed.
73  
74 =item timeout => $seconds
75  
76 HTTP inactivity timeout, defaulting to 300 seconds. Use the common
77 C<request_timeout> option for an overall tool-call deadline.
78  
79 =item headers => { %headers }
80  
81 Additional HTTP headers. Protocol headers and an explicitly configured
82 bearer header are supplied by this module.
83  
84 =item max_size => $bytes
85  
86 Bounds a JSON response or an individual buffered SSE event, defaulting to
87 8 MiB. SSE notifications are delivered incrementally rather than after
88 the HTTP response ends.
89  
90 =back
91  
92 C<proxy>, C<tls_ctx>, C<handle_params>, C<sessionid>, C<on_prepare>,
93 C<on_connect> and C<tcp_connect> are passed to L<AnyEvent::HTTP>.
94 No HTTP cookies or Basic authentication are supplied by this module.
95 Redirects and automatic HTTP retries are disabled.
96  
97 Legacy session IDs are retained from initialization. An expired session fails
98 outstanding requests; a later operation can initialize again. Legacy GET
99 streams and the old separate SSE endpoint transport are not implemented.
100  
101 =back
102  
103 =cut
104  
105 package AnyEvent::MCP::Client::HTTP;
106  
107 54 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 54 ▶use parent "AnyEvent::MCP::Client";
Subroutine BEGIN: called CC=1 SCAR=0.0
109 54 ▶use AnyEvent::HTTP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
110 54 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
111 54 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
112 54 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 66 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
115 66 my ($class, %kv) = @_;
116  
117 66 ▶ if (defined $kv{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kv{"name"}) 17 49 66
118 17 require AnyEvent::MCP::Config;
119 17 ▶ my $settings = AnyEvent::MCP::Config->global->{section}{"client $kv{name}"} || {};
Condition100%2/2
'AnyEvent::MCP::Config'->global->{'section'}{"client $kv{'name'}"} || {}
l!l
215
MC/DC100%1/1
'AnyEvent::MCP::Config'->global->{'section'}{"client $kv{'name'}"} || {}
'AnyEvent::MCP::Config'->global->{'section'}{"client $kv{'name'}"}
Truth table100%2/2
A
A= 'AnyEvent::MCP::Config'->global->{'section'}{"client $kv{'name'}"}
Aresult
11
00
120 %kv = (
121 17 ▶ (map { exists $settings->{$_} ? ($_ => $settings->{$_}) : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $settings->{$_} ? : 6 45 51
122 qw(url bearer timeout)),
123 %kv,
124 );
125 }
126  
127 defined $kv{url}
128 66 ▶ or die "HTTP client requires a URL\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $kv{"url"} or die "HTTP client requires a URL\n" 66 0 66
129 !exists $kv{username} && !exists $kv{password}
130 66 ▶ or die "HTTP Basic authentication is unsupported\n";
Branch: 1 branch
BranchTrueFalseTotal
exists $kv{"username"} || exists $kv{"password"} and die "HTTP Basic authentication is unsupported\n" 2 64 66
Condition66%2/3
exists $kv{"username"} or exists $kv{"password"}
l!l&&r!l&&!r
2064
MC/DC50%1/2
exists $kv{"username"} or exists $kv{"password"}
exists $kv{"username"} exists $kv{"password"}
Truth table66%2/3
A or B
A= exists $kv{"username"}B= exists $kv{"password"}
ABresult
1X1
011
000
131 64 ▶ die "Invalid bearer token\n" if defined $kv{bearer} && $kv{bearer} !~ /\A[^\s]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $kv{"bearer"} and not $kv{"bearer"} =~ /\A[^\s]+\z/u 1 63 64
Condition100%3/3
defined $kv{"bearer"} and not $kv{"bearer"} =~ /\A[^\s]+\z/u
!ll&&!rl&&r
40231
MC/DC100%2/2
defined $kv{"bearer"} and not $kv{"bearer"} =~ /\A[^\s]+\z/u
defined $kv{"bearer"} not $kv{"bearer"} =~ /\A[^\s]+\z/u
Truth table100%3/3
A and not(B)
A= defined $kv{"bearer"}B= not $kv{"bearer"} =~ /\A[^\s]+\z/u
ABresult
0X0
100
111
132  
133 63 $class->SUPER::new (timeout => 300, %kv)
134 }
135  
136 182 ▶sub _send {
Subroutine _send: called CC=20 SCAR=31.9
137 182 my ($self, $message, $done) = @_;
138  
139 my $key = exists $message->{id} && !exists $message->{result} && !exists $message->{error}
140 182 ▶ ? $message->{id} : "send:" . ++$self->{send_id};
Branch: 1 branch
BranchTrueFalseTotal
exists $message->{'id'} && !exists $message->{'result'} && !exists $message->{'error'} ? : 174 8 182
Condition66%4/6
exists $message->{"id"} and not exists $message->{"result"} and not exists $message->{"error"}
!ll&&!rl&&r
80174
exists $message->{"id"} and not exists $message->{"result"}
!ll&&!rl&&r
80174
MC/DC33%1/3
exists $message->{"id"} and not exists $message->{"result"} and not exists $message->{"error"}
exists $message->{"id"} not exists $message->{"result"} not exists $message->{"error"}
Truth table50%2/4
A and not(B) and not(C)
A= exists $message->{"id"}B= not exists $message->{"result"}C= not exists $message->{"error"}
ABCresult
0XX0
10X0
1100
1111
141 182 my $generation = $self->{generation};
142 my %headers = (
143 182 ▶ %{$self->{headers} || {}},
Condition50%1/2
$self->{'headers'} || {}
l!l
0182
MC/DC0%0/1
$self->{'headers'} || {}
$self->{'headers'}
Truth table50%1/2
A
A= $self->{'headers'}
Aresult
11
00
144 "content-type" => "application/json",
145 accept => "application/json, text/event-stream",
146 );
147  
148 182 ▶ $headers{authorization} = "Bearer $self->{bearer}" if defined $self->{bearer};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"bearer"} 62 120 182
149 182 ▶ $headers{"mcp-protocol-version"} = $self->{protocol_version} if defined $self->{protocol_version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"protocol_version"} 182 0 182
150 $headers{"mcp-session-id"} = $self->{session}
151 182 ▶ if $self->{protocol_version} lt "2026" && defined $self->{session};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"protocol_version"} lt 2026 and defined $self->{"session"} 4 178 182
Condition100%3/3
$self->{"protocol_version"} lt 2026 and defined $self->{"session"}
!ll&&!rl&&r
161174
MC/DC100%2/2
$self->{"protocol_version"} lt 2026 and defined $self->{"session"}
$self->{"protocol_version"} lt 2026 defined $self->{"session"}
Truth table100%3/3
A and B
A= $self->{"protocol_version"} lt 2026B= defined $self->{"session"}
ABresult
0X0
100
111
152  
153 182 ▶ if ($self->{protocol_version} ge "2026" && exists $message->{method} && exists $message->{id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"protocol_version"} ge 2026 and exists $message->{"method"} and exists $message->{"id"}) 160 22 182
Condition83%5/6
$self->{"protocol_version"} ge 2026 and exists $message->{"method"} and exists $message->{"id"}
!ll&&!rl&&r
211160
$self->{"protocol_version"} ge 2026 and exists $message->{"method"}
!ll&&!rl&&r
210161
MC/DC66%2/3
$self->{"protocol_version"} ge 2026 and exists $message->{"method"} and exists $message->{"id"}
$self->{"protocol_version"} ge 2026 exists $message->{"method"} exists $message->{"id"}
Truth table75%3/4
A and B and C
A= $self->{"protocol_version"} ge 2026B= exists $message->{"method"}C= exists $message->{"id"}
ABCresult
0XX0
10X0
1100
1111
154 160 $headers{"mcp-method"} = $message->{method};
155 160 ▶ if ($message->{method} =~ /\A(?:tools\/call|prompts\/get|resources\/read)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message->{"method"} =~ m[\A(?:tools/call|prompts/get|resources/read)\z]u) 76 84 160
156 76 ▶ my $name = exists $message->{params}{name} ? $message->{params}{name} : $message->{params}{uri};
Branch: 1 branch
BranchTrueFalseTotal
exists $message->{'params'}{'name'} ? : 76 0 76
157 76 ▶ $headers{"mcp-name"} = $name =~ /[^\x20-\x7e]/
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /[^\x20-\x7e]/u ? : 1 75 76
158 ? "=?base64?" . MIME::Base64::encode_base64 (AnyEvent::MCP::utf8enc ($name), "") . "?="
159 : $name;
160 }
161 }
162  
163 182 my ($buffer, $sse, $received, $failure) = ("", 0, 0);
164 182 ▶ my $limit = $self->{max_size} || 8 * 1024 * 1024;
Condition50%1/2
$self->{'max_size'} || 8388608
l!l
0182
MC/DC0%0/1
$self->{'max_size'} || 8388608
$self->{'max_size'}
Truth table50%1/2
A
A= $self->{'max_size'}
Aresult
11
00
165 182 weaken $self;
166  
167 166 ▶ my $deliver = sub {
Subroutine __ANON__: called CC=6 SCAR=19.9
168 166 my ($response) = @_;
169  
170 166 ▶ if (ref $response eq "HASH" && !exists $response->{method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq "HASH" and not exists $response->{"method"}) 165 1 166
Condition66%2/3
ref $response eq "HASH" and not exists $response->{"method"}
!ll&&!rl&&r
01165
MC/DC50%1/2
ref $response eq "HASH" and not exists $response->{"method"}
ref $response eq "HASH" not exists $response->{"method"}
Truth table66%2/3
A and not(B)
A= ref $response eq "HASH"B= not exists $response->{"method"}
ABresult
0X0
100
111
171 die "HTTP response id mismatch\n"
172 unless exists $message->{id} && defined $response->{id}
173 165 ▶ && "$response->{id}" eq "$message->{id}";
Branch: 1 branch
BranchTrueFalseTotal
unless exists $message->{"id"} and defined $response->{"id"} and qq[$response->{"id"}] eq qq[$message->{"id"}] 0 165 165
Condition33%2/6
exists $message->{"id"} and defined $response->{"id"} and qq[$response->{"id"}] eq qq[$message->{"id"}]
!ll&&!rl&&r
00165
exists $message->{"id"} and defined $response->{"id"}
!ll&&!rl&&r
00165
MC/DC0%0/3
exists $message->{"id"} and defined $response->{"id"} and qq[$response->{"id"}] eq qq[$message->{"id"}]
exists $message->{"id"} defined $response->{"id"} qq[$response->{"id"}] eq qq[$message->{"id"}]
Truth table25%1/4
A and B and C
A= exists $message->{"id"}B= defined $response->{"id"}C= qq[$response->{"id"}] eq qq[$message->{"id"}]
ABCresult
0XX0
10X0
1100
1111
174 165 $received = 1;
175 }
176 166 $self->_receive ($response);
177 182 };
178  
179 182 my $guard;
180 182 my $ok = eval {
181 $guard = AnyEvent::HTTP::http_request POST => $self->{url},
182 1456 ▶ (map { exists $self->{$_} ? ($_ => $self->{$_}) : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$_} ? : 182 1274 1456
183 qw(timeout proxy tls_ctx handle_params sessionid on_prepare on_connect tcp_connect)),
184 headers => \%headers,
185 body => JSON::XS::encode_json ($message),
186 recurse => 0,
187 persistent => 0,
188 181 ▶ on_header => sub {
Subroutine __ANON__: called CC=7 SCAR=20.2
189 181 my ($hdr) = @_;
190  
191 181 ▶ return 0 unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 181 181
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00181
MC/DC0%0/2
$self and $self->{"generation"} == $generation
$self $self->{"generation"} == $generation
Truth table33%1/3
A and B
A= $selfB= $self->{"generation"} == $generation
ABresult
0X0
100
111
192 181 $sse = $hdr->{"content-type"} =~ m{\Atext/event-stream(?:\s*;|\z)}i;
193 181 ▶ if ($message->{method} eq "initialize" && $hdr->{Status} >= 200 && $hdr->{Status} < 300
Branch: 1 branch
BranchTrueFalseTotal
if ($message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 and defined $hdr->{"mcp-session-id"}) 2 179 181
Condition77%7/9
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 and defined $hdr->{"mcp-session-id"}
!ll&&!rl&&r
17452
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
17407
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200
!ll&&!rl&&r
17407
MC/DC50%2/4
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 and defined $hdr->{"mcp-session-id"}
$message->{"method"} eq "initialize" $hdr->{"Status"} >= 200 $hdr->{"Status"} < 300 defined $hdr->{"mcp-session-id"}
Truth table60%3/5
A and B and C and D
A= $message->{"method"} eq "initialize"B= $hdr->{"Status"} >= 200C= $hdr->{"Status"} < 300D= defined $hdr->{"mcp-session-id"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
194 && defined $hdr->{"mcp-session-id"}) {
195 2 $self->{session} = $hdr->{"mcp-session-id"};
196 }
197 1
198 181 },
199 169 ▶ on_body => sub {
Subroutine __ANON__: called CC=9 SCAR=23.0
200 169 my ($chunk, $hdr) = @_;
201  
202 169 ▶ return 0 unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 169 169
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00169
MC/DC0%0/2
$self and $self->{"generation"} == $generation
$self $self->{"generation"} == $generation
Truth table33%1/3
A and B
A= $selfB= $self->{"generation"} == $generation
ABresult
0X0
100
111
203 169 $buffer .= $chunk;
204  
205 169 my $ok = eval {
206 169 ▶ if ($sse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sse) 3 166 169
207 3 ▶ while ($buffer =~ s/\A(.*?)(?:\r\n\r\n|\n\n|\r\r)//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ s/\A(.*?)(?:\r\n\r\n|\n\n|\r\r)//su) 2 3 5
208 2 my $event = $1;
209 2 ▶ die "SSE event exceeds size limit\n" if length $event > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if length $event > $limit 0 2 2
210 2 my @data = $event =~ /^data:[ \t]?(.*?)(?:\r?$)/mg;
211 2 ▶ $deliver->(JSON::XS::decode_json join "\n", @data) if @data;
Branch: 1 branch
BranchTrueFalseTotal
if @data 2 0 2
212 }
213 }
214 169 ▶ die "HTTP response exceeds size limit\n" if length $buffer > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if length $buffer > $limit 0 169 169
215 169 1
216 };
217 169 ▶ $failure = $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 169 169
218 169 $ok
219 },
220 182 ▶ sub {
Subroutine __ANON__: called CC=19 SCAR=31.7
221 182 my (undef, $hdr) = @_;
222  
223 182 ▶ return unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 182 182
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00182
MC/DC0%0/2
$self and $self->{"generation"} == $generation
$self $self->{"generation"} == $generation
Truth table33%1/3
A and B
A= $selfB= $self->{"generation"} == $generation
ABresult
0X0
100
111
224 182 delete $self->{http_requests}{$key};
225  
226 182 ▶ if ($hdr->{Status} == 404 && defined $self->{session} && !$received) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr->{"Status"} == 404 and defined $self->{"session"} and not $received) 2 180 182
Condition83%5/6
$hdr->{"Status"} == 404 and defined $self->{"session"} and not $received
!ll&&!rl&&r
18002
$hdr->{"Status"} == 404 and defined $self->{"session"}
!ll&&!rl&&r
17642
MC/DC66%2/3
$hdr->{"Status"} == 404 and defined $self->{"session"} and not $received
$hdr->{"Status"} == 404 defined $self->{"session"} not $received
Truth table75%3/4
A and B and not(C)
A= $hdr->{"Status"} == 404B= defined $self->{"session"}C= not $received
ABCresult
0XX0
10X0
1100
1111
227 2 return $self->close ("MCP session expired")
228 }
229  
230 180 my $ok = eval {
231 180 ▶ die $failure if $failure;
Branch: 1 branch
BranchTrueFalseTotal
if $failure 0 180 180
232 180 ▶ if (!$sse && length $buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $sse and length $buffer) 164 16 180
Condition100%3/3
not $sse and length $buffer
!ll&&!rl&&r
115164
MC/DC100%2/2
not $sse and length $buffer
not $sse length $buffer
Truth table100%3/3
not(A) and B
A= not $sseB= length $buffer
ABresult
0X0
100
111
233 164 my $response = eval { JSON::XS::decode_json $buffer };
234 164 ▶ if (ref $response eq "HASH" && ($hdr->{Status} >= 200 && $hdr->{Status} < 300
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq 'HASH' and $hdr->{'Status'} >= 200 && $hdr->{'Status'} < 300 || ref $response->{'error'} eq 'HASH') { } 164 0 164
Condition55%5/9
ref $response eq "HASH" and $hdr->{"Status"} >= 200 && $hdr->{"Status"} < 300 || ref $response->{"error"} eq "HASH"
!ll&&!rl&&r
00164
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 or ref $response->{"error"} eq "HASH"
l!l&&r!l&&!r
15860
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
06158
MC/DC0%0/4
ref $response eq "HASH" and $hdr->{"Status"} >= 200 && $hdr->{"Status"} < 300 || ref $response->{"error"} eq "HASH"
ref $response eq "HASH" $hdr->{"Status"} >= 200 $hdr->{"Status"} < 300 ref $response->{"error"} eq "HASH"
Truth table33%2/6
A and B and C or D
A= ref $response eq "HASH"B= $hdr->{"Status"} >= 200C= $hdr->{"Status"} < 300D= ref $response->{"error"} eq "HASH"
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
235 || ref $response->{error} eq "HASH")) {
236 164 $deliver->($response);
237 } else {
238 0 die "HTTP $hdr->{Status} $hdr->{Reason}\n"
239 }
240 }
241  
242 die "HTTP $hdr->{Status} $hdr->{Reason}\n"
243 180 ▶ unless $hdr->{Status} >= 200 && $hdr->{Status} < 300;
Branch: 1 branch
BranchTrueFalseTotal
unless $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 13 167 180
Condition66%2/3
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
013167
MC/DC50%1/2
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
$hdr->{"Status"} >= 200 $hdr->{"Status"} < 300
Truth table66%2/3
A and B
A= $hdr->{"Status"} >= 200B= $hdr->{"Status"} < 300
ABresult
0X0
100
111
244 die "HTTP response has no matching JSON-RPC reply\n"
245 167 ▶ if exists $message->{id} && exists $message->{method} && !$received;
Branch: 1 branch
BranchTrueFalseTotal
if exists $message->{"id"} and exists $message->{"method"} and not $received 0 167 167
Condition66%4/6
exists $message->{"id"} and exists $message->{"method"} and not $received
!ll&&!rl&&r
81590
exists $message->{"id"} and exists $message->{"method"}
!ll&&!rl&&r
80159
MC/DC0%0/3
exists $message->{"id"} and exists $message->{"method"} and not $received
exists $message->{"id"} exists $message->{"method"} not $received
Truth table50%2/4
A and B and not(C)
A= exists $message->{"id"}B= exists $message->{"method"}C= not $received
ABCresult
0XX0
10X0
1100
1111
246 167 1
247 };
248 180 ▶ $done->($ok ? (1, undef) : (0, { transport => 1, message => "$@" }));
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 167 13 180
249 182 };
250 182 1
251 };
252 182 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 182 0 182
253 182 ▶ $self->{http_requests}{$key} = $guard if $self && $guard;
Branch: 1 branch
BranchTrueFalseTotal
if $self and $guard 182 0 182
Condition33%1/3
$self and $guard
!ll&&!rl&&r
00182
MC/DC0%0/2
$self and $guard
$self $guard
Truth table33%1/3
A and B
A= $selfB= $guard
ABresult
0X0
100
111
254 } else {
255 0 $done->(0, { transport => 1, message => "$@" });
256 }
257 }
258  
259 0 ▶sub _abort {
Subroutine _abort: not called CC=1 SCAR=6.9
260 0 my ($self, $id) = @_;
261  
262 0 delete $self->{http_requests}{$id};
263 }
264  
265 119 ▶sub _shutdown {
Subroutine _shutdown: called CC=1 SCAR=0.0
266 119 my ($self) = @_;
267  
268 119 delete @$self{qw(http_requests session)};
269 }
270  
271 54 1
« blib/lib/AnyEvent/MCP/Server/HTTP.pm ↑ Summary blib/lib/AnyEvent/MCP/Client.pm »