Connector/Proxy/http.pm

filter: Statementstmt 85.1% 46 / 54 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 5 totaltotal 80.5% 62 / 77 CC 4 SCAR 5.1
CC
4
Cov
85%
__ANON__
3.3
__ANON__
2.0
__ANON__
2.0
CRAP 1.7
« Connector.pm ↑ Summary
1 package AnyEvent::Connector::Proxy::http;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
7 19 my ($class, $uri) = @_;
8 19 my $self = bless {
9 uri => $uri
10 }, $class;
11 19 return $self;
12 }
13  
14 37 ▶sub uri_string {
Subroutine uri_string: called CC=1 SCAR=0.0
Pod undocumented
15 37 my ($self) = @_;
16 37 return $self->{uri}->as_string;
17 }
18  
19 4 ▶sub host {
Subroutine host: called CC=1 SCAR=0.0
Pod undocumented
20 4 my ($self) = @_;
21 4 return $self->{uri}->host;
22 }
23  
24 4 ▶sub port {
Subroutine port: called CC=1 SCAR=0.0
Pod undocumented
25 4 my ($self) = @_;
26 4 return $self->{uri}->port;
27 }
28  
29 3 ▶sub establish_proxy {
Subroutine establish_proxy: called CC=1 SCAR=0.1
Pod undocumented
30 3 my ($self, $fh, $target_host, $target_port, $cb) = @_;
31 3 my $ah;
32 my $header_reader;
33 $ah = AnyEvent::Handle->new(
34 fh => $fh,
35 1 ▶ on_error => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 ## TODO: how should we report the error detail?
37 1 undef $ah;
38 1 undef $header_reader;
39 1 $cb->(0);
40 },
41 0 ▶ on_eof => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 undef $ah;
43 0 undef $header_reader;
44 0 $cb->(0);
45 },
46 3 );
47 3 $ah->push_write(
48 "CONNECT $target_host:$target_port HTTP/1.1\r\n" .
49 "Host: $target_host:$target_port\r\n\r\n"
50 );
51 2 ▶ $header_reader = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
52 2 my ($h, $line) = @_;
53 2 ▶ if($line eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "") 1 1 2
54 1 $ah->destroy();
55 1 undef $ah;
56 1 undef $header_reader;
57 1 $cb->(1);
58 1 return;
59 }
60 1 $ah->push_read(line => $header_reader);
61 3 };
62 2 ▶ $ah->push_read(line => sub {
Subroutine __ANON__: called CC=3 SCAR=11.9
63 2 my ($h, $line) = @_;
64 2 ▶ if($line !~ qr{^HTTP/1\S* +(\d{3})}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ qr"^HTTP/1\S* +(\d{3})") 1 1 2
65 1 $ah->destroy();
66 1 undef $ah;
67 1 undef $header_reader;
68 1 $cb->(0);
69 1 return;
70 }
71 1 my $status = $1;
72 1 ▶ if(int($status / 100) != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $status / 100 != 2) 0 1 1
73 0 $ah->destroy();
74 0 undef $ah;
75 0 undef $header_reader;
76 0 $cb->(0);
77 0 return;
78 }
79 1 $ah->push_read(line => $header_reader);
80 3 });
81 }
82  
83  
84 4 1;
85  
86 __END__
« Connector.pm ↑ Summary