line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::HTTP::UA::LWPClass; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
189524
|
use strict; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
198
|
|
4
|
7
|
|
|
7
|
|
43
|
use warnings; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
140
|
|
5
|
7
|
|
|
7
|
|
476
|
use URI; |
|
7
|
|
|
|
|
3834
|
|
|
7
|
|
|
|
|
158
|
|
6
|
7
|
|
|
7
|
|
32
|
use parent 'Test2::Tools::HTTP::UA'; |
|
7
|
|
|
|
|
26
|
|
|
7
|
|
|
|
|
38
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Global LWP user agent wrapper for Test2::Tools::HTTP |
9
|
|
|
|
|
|
|
our $VERSION = '0.11'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %orig; |
13
|
|
|
|
|
|
|
my $ua; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub instrument |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
0
|
5
|
my($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
5
|
require LWP::Protocol; |
20
|
1
|
|
|
|
|
539
|
require LWP::UserAgent; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
13141
|
foreach my $proto (qw( http https )) |
23
|
|
|
|
|
|
|
{ |
24
|
2
|
|
66
|
|
|
8
|
$orig{$proto} ||= do { |
25
|
2
|
|
|
|
|
7
|
my $orig = LWP::Protocol::implementor($proto); |
26
|
2
|
|
|
|
|
26531
|
LWP::Protocol::implementor($proto, 'Test2::Tools::HTTP::UA::LWPClass::Proto'); |
27
|
2
|
|
|
|
|
22
|
$orig; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
33
|
|
|
8
|
$ua ||= LWP::UserAgent->new; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub request |
35
|
|
|
|
|
|
|
{ |
36
|
3
|
|
|
3
|
0
|
3369
|
my($self, $req, %options) = @_; |
37
|
|
|
|
|
|
|
|
38
|
3
|
50
|
33
|
|
|
8
|
if($self->apps->uri_to_app($req->uri) && $req->uri =~ /^\//) |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
|
|
0
|
$req->uri( |
41
|
|
|
|
|
|
|
URI->new_abs($req->uri, $self->apps->base_url), |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $res = $options{follow_redirects} |
46
|
3
|
100
|
|
|
|
42
|
? $ua->request($req) |
47
|
|
|
|
|
|
|
: $ua->simple_request($req); |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
8346
|
if(my $warning = $res->header('Client-Warning')) |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
0
|
|
|
0
|
$self->error( |
52
|
|
|
|
|
|
|
"connection error: " . ($res->decoded_content || $warning), |
53
|
|
|
|
|
|
|
$res, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
131
|
$res; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->register('LWP::UserAgent', 'class'); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
package Test2::Tools::HTTP::UA::LWPClass::Proto; |
63
|
|
|
|
|
|
|
|
64
|
7
|
|
|
7
|
|
2293
|
use parent qw(LWP::Protocol); |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
37
|
|
65
|
7
|
|
|
7
|
|
42591
|
use HTTP::Message::PSGI qw( req_to_psgi res_from_psgi ); |
|
7
|
|
|
|
|
53256
|
|
|
7
|
|
|
|
|
1149
|
|
66
|
|
|
|
|
|
|
|
67
|
5
|
|
|
5
|
|
21
|
sub apps { Test2::Tools::HTTP::UA->apps } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub request |
70
|
|
|
|
|
|
|
{ |
71
|
5
|
|
|
5
|
|
3868
|
my($self, $req, $proxy, $arg, @rest) = @_; |
72
|
|
|
|
|
|
|
|
73
|
5
|
50
|
|
|
|
12
|
if(my $app = $self->apps->uri_to_app($req->uri)) |
74
|
|
|
|
|
|
|
{ |
75
|
5
|
|
|
|
|
15
|
my $env = req_to_psgi $req; |
76
|
5
|
|
|
|
|
3204
|
my $res = res_from_psgi $app->($env); |
77
|
5
|
|
|
|
|
726
|
my $content = $res->content; |
78
|
5
|
|
|
|
|
51
|
$res->content(''); |
79
|
5
|
|
|
|
|
75
|
return $self->collect_once($arg, $res, $content); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
|
|
|
return $orig{$self->{scheme}}->new($self->{scheme}, $self->{ua})->request($req, $proxy, $arg, @rest); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |