line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
14
|
use v5.10.0; |
|
1
|
|
|
|
|
3
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package JMAP::Tester::UA::LWP 0.102; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
with 'JMAP::Tester::Role::UA'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
290
|
use Carp (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
14
|
|
10
|
1
|
|
|
1
|
|
4
|
use Future; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
494
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has lwp => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
lazy => 1, |
15
|
|
|
|
|
|
|
default => sub { |
16
|
|
|
|
|
|
|
my ($self) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
require LWP::UserAgent; |
19
|
|
|
|
|
|
|
my $lwp = LWP::UserAgent->new; |
20
|
|
|
|
|
|
|
$lwp->cookie_jar({}); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$lwp->default_header('Content-Type' => 'application/json'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ($ENV{IGNORE_INVALID_CERT}) { |
25
|
|
|
|
|
|
|
$lwp->ssl_opts(SSL_verify_mode => 0, verify_hostname => 0); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $lwp; |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub set_cookie { |
33
|
0
|
|
|
0
|
0
|
|
my ($self, $arg) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
for (qw(api_uri name value)) { |
36
|
0
|
0
|
|
|
|
|
Carp::confess("can't set_cookie without $_") unless $arg->{$_}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $uri = URI->new($arg->{api_uri}); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->lwp->cookie_jar->set_cookie( |
42
|
|
|
|
|
|
|
1, |
43
|
|
|
|
|
|
|
$arg->{name}, |
44
|
|
|
|
|
|
|
$arg->{value}, |
45
|
|
|
|
|
|
|
'/', |
46
|
|
|
|
|
|
|
$arg->{domain} // $uri->host, |
47
|
|
|
|
|
|
|
$uri->port, |
48
|
|
|
|
|
|
|
0, |
49
|
|
|
|
|
|
|
($uri->port == 443 ? 1 : 0), |
50
|
|
|
|
|
|
|
86400, |
51
|
|
|
|
|
|
|
0, |
52
|
|
|
|
|
|
|
$arg->{rest} || {}, |
53
|
0
|
0
|
0
|
|
|
|
); |
|
|
|
0
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub scan_cookies { |
57
|
0
|
|
|
0
|
0
|
|
my ($self, $callback) = @_; |
58
|
0
|
|
|
|
|
|
return $self->lwp->cookie_jar->scan($callback); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_default_header { |
62
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return scalar $self->lwp->default_header($name); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub set_default_header { |
68
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $value) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$self->lwp->default_header($name, $value); |
71
|
0
|
|
|
|
|
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub request { |
75
|
0
|
|
|
0
|
0
|
|
my ($self, $tester, $req, $log_type, $log_extra) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
Carp::cluck("something very strange happened") unless $tester->can('_logger'); |
78
|
0
|
|
|
|
|
|
my $logger = $tester->_logger; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
0
|
|
|
|
my $log_method = "log_" . ($log_type // 'jmap') . '_request'; |
81
|
0
|
0
|
|
|
|
|
if ($logger->can($log_method)) { |
82
|
|
|
|
|
|
|
$self->lwp->set_my_handler(request_send => sub { |
83
|
0
|
|
|
0
|
|
|
my ($req) = @_; |
84
|
0
|
0
|
|
|
|
|
$logger->$log_method({ |
85
|
|
|
|
|
|
|
($log_extra ? %$log_extra : ()), |
86
|
|
|
|
|
|
|
http_request => $req, |
87
|
|
|
|
|
|
|
}); |
88
|
0
|
|
|
|
|
|
return; |
89
|
0
|
|
|
|
|
|
}); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $http_res = $self->lwp->request($req); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Clear our handler, or it will get called for |
95
|
|
|
|
|
|
|
# any http request our ua makes! |
96
|
0
|
|
|
|
|
|
$self->lwp->set_my_handler(request_send => undef); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return Future->done($http_res); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
1
|
|
13
|
no Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |