line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::HTTP::UA::LWPClass; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
220087
|
use strict; |
|
7
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
267
|
|
4
|
7
|
|
|
7
|
|
56
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
163
|
|
5
|
7
|
|
|
7
|
|
591
|
use URI; |
|
7
|
|
|
|
|
4690
|
|
|
7
|
|
|
|
|
180
|
|
6
|
7
|
|
|
7
|
|
472
|
use parent 'Test2::Tools::HTTP::UA'; |
|
7
|
|
|
|
|
358
|
|
|
7
|
|
|
|
|
48
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Global LWP user agent wrapper for Test2::Tools::HTTP |
9
|
|
|
|
|
|
|
our $VERSION = '0.09'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %orig; |
13
|
|
|
|
|
|
|
my $ua; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub instrument |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
0
|
8
|
my($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
6
|
require LWP::Protocol; |
20
|
1
|
|
|
|
|
633
|
require LWP::UserAgent; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
12368
|
foreach my $proto (qw( http https )) |
23
|
|
|
|
|
|
|
{ |
24
|
2
|
|
66
|
|
|
14
|
$orig{$proto} ||= do { |
25
|
2
|
|
|
|
|
10
|
my $orig = LWP::Protocol::implementor($proto); |
26
|
2
|
|
|
|
|
32885
|
LWP::Protocol::implementor($proto, 'Test2::Tools::HTTP::UA::LWPClass::Proto'); |
27
|
2
|
|
|
|
|
33
|
$orig; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
33
|
|
|
16
|
$ua ||= LWP::UserAgent->new; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub request |
35
|
|
|
|
|
|
|
{ |
36
|
3
|
|
|
3
|
0
|
4186
|
my($self, $req, %options) = @_; |
37
|
|
|
|
|
|
|
|
38
|
3
|
50
|
33
|
|
|
15
|
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
|
|
|
|
58
|
? $ua->request($req) |
47
|
|
|
|
|
|
|
: $ua->simple_request($req); |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
10805
|
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
|
|
|
|
|
162
|
$res; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->register('LWP::UserAgent', 'class'); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
package Test2::Tools::HTTP::UA::LWPClass::Proto; |
63
|
|
|
|
|
|
|
|
64
|
7
|
|
|
7
|
|
2515
|
use parent qw(LWP::Protocol); |
|
7
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
30
|
|
65
|
7
|
|
|
7
|
|
58139
|
use HTTP::Message::PSGI qw( req_to_psgi res_from_psgi ); |
|
7
|
|
|
|
|
62209
|
|
|
7
|
|
|
|
|
1369
|
|
66
|
|
|
|
|
|
|
|
67
|
5
|
|
|
5
|
|
29
|
sub apps { Test2::Tools::HTTP::UA->apps } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub request |
70
|
|
|
|
|
|
|
{ |
71
|
5
|
|
|
5
|
|
5274
|
my($self, $req, $proxy, $arg, @rest) = @_; |
72
|
|
|
|
|
|
|
|
73
|
5
|
50
|
|
|
|
18
|
if(my $app = $self->apps->uri_to_app($req->uri)) |
74
|
|
|
|
|
|
|
{ |
75
|
5
|
|
|
|
|
21
|
my $env = req_to_psgi $req; |
76
|
5
|
|
|
|
|
4294
|
my $res = res_from_psgi $app->($env); |
77
|
5
|
|
|
|
|
936
|
my $content = $res->content; |
78
|
5
|
|
|
|
|
62
|
$res->content(''); |
79
|
5
|
|
|
|
|
96
|
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__ |