line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::HTTP::Client; |
2
|
|
|
|
|
|
|
$Net::HTTP::Client::VERSION = '0.012'; |
3
|
2
|
|
|
2
|
|
16130
|
use 5.10.0; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
81
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
57
|
|
5
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
104
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
449
|
use Errno qw(EINTR EIO :POSIX); |
|
2
|
|
|
|
|
1027
|
|
|
2
|
|
|
|
|
863
|
|
8
|
2
|
|
|
2
|
|
1011
|
use HTTP::Response; |
|
2
|
|
|
|
|
44096
|
|
|
2
|
|
|
|
|
80
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
904
|
use parent qw/Net::HTTP/; |
|
2
|
|
|
|
|
518
|
|
|
2
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $DEBUG = 0; |
13
|
|
|
|
|
|
|
my $used = 0; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
5
|
|
|
5
|
1
|
2126
|
my $class = shift; |
17
|
5
|
|
|
|
|
119
|
$class->SUPER::new(@_); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub request { |
21
|
6
|
|
|
6
|
1
|
1007763
|
my ($self, $method, $uri, @headers) = @_; |
22
|
|
|
|
|
|
|
|
23
|
6
|
100
|
|
|
|
45
|
my $content = (@headers % 2) ? pop @headers : ''; |
24
|
|
|
|
|
|
|
|
25
|
6
|
100
|
50
|
|
|
59
|
if ($uri !~ /^\//) { |
|
|
50
|
33
|
|
|
|
|
26
|
4
|
|
|
|
|
15
|
my $host; |
27
|
4
|
|
|
|
|
25
|
($host, $uri) = split /\//, $uri, 2; |
28
|
4
|
50
|
|
|
|
22
|
warn "New connection to host $host\n" if $DEBUG; |
29
|
4
|
|
50
|
|
|
24
|
$self = $self->new(Host => $host) || die $@; |
30
|
4
|
|
100
|
|
|
14374
|
$uri = '/' . ($uri // ''); |
31
|
|
|
|
|
|
|
} elsif ($used and !$self->keep_alive // 0) { |
32
|
0
|
0
|
|
|
|
0
|
warn 'Reconnecting to ', $self->peerhost, ':', $self->peerport, "\n" if $DEBUG; |
33
|
0
|
|
0
|
|
|
0
|
$self = $self->new(Host => $self->peerhost, PeerPort => $self->peerport) || die $@; |
34
|
|
|
|
|
|
|
} |
35
|
6
|
|
|
|
|
26
|
$used = 1; |
36
|
6
|
50
|
|
|
|
14
|
warn "$method $uri\n" if $DEBUG; |
37
|
|
|
|
|
|
|
|
38
|
6
|
|
|
|
|
27
|
my $success = $self->print( $self->format_request($method => $uri, @headers, $content) ); |
39
|
6
|
|
|
|
|
3811
|
my ($status, $message, @res_headers) = $self->read_response_headers; |
40
|
6
|
|
|
|
|
41212
|
HTTP::Response->new($status, $message, \@res_headers, $self->get_content()); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get_content { |
44
|
6
|
|
|
6
|
1
|
14
|
my ($self) = @_; |
45
|
6
|
|
|
|
|
13
|
my $content = ''; |
46
|
6
|
|
|
|
|
9
|
while (1) { |
47
|
11
|
|
|
|
|
13
|
my $buf; |
48
|
11
|
|
|
|
|
41
|
my $n = $self->read_entity_body($buf, 1024); |
49
|
11
|
0
|
33
|
|
|
347
|
die "read failed: $!" unless defined $n or $!{EINTR} or $!{EAGAIN}; |
|
|
|
33
|
|
|
|
|
50
|
11
|
100
|
|
|
|
22
|
last unless $n; |
51
|
5
|
|
|
|
|
11
|
$content .= $buf; |
52
|
|
|
|
|
|
|
} |
53
|
6
|
|
|
|
|
54
|
$content; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |