line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::ACME::HTTP_Tiny; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=encoding utf-8 |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Net::ACME::HTTP_Tiny - HTTP client for Net::ACME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Net::ACME::HTTP_Tiny; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $http = Net::ACME::HTTP_Tiny->new(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#NOTE: Unlike HTTP::Tiny’s method, this will die() if the HTTP |
16
|
|
|
|
|
|
|
#session itself fails--for example, if the network connection was |
17
|
|
|
|
|
|
|
#interrupted. These will be Net::ACME::X::HTTP::Network instances. |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
#This also fails on HTTP errors (4xx and 5xx). The errors are |
20
|
|
|
|
|
|
|
#instances of Net::ACME::X::HTTP::Protocol. |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
my $resp_obj = $http->post_form( $the_url, \%the_form_post ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This module largely duplicates the work of C, just without the |
27
|
|
|
|
|
|
|
dependency on C (which brings in a mess of other undesirables). |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
The chief benefit is that C and related methods will return |
30
|
|
|
|
|
|
|
instances of C rather than simple hashes. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This also always verifies remote SSL connections and always Cs if |
33
|
|
|
|
|
|
|
either the network connection fails or the protocol indicates an error |
34
|
|
|
|
|
|
|
(4xx or 5xx). |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
7
|
|
|
7
|
|
23
|
use strict; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
167
|
|
39
|
7
|
|
|
7
|
|
28
|
use warnings; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
143
|
|
40
|
|
|
|
|
|
|
|
41
|
7
|
|
|
7
|
|
19
|
use parent qw( HTTP::Tiny ); |
|
7
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
25
|
|
42
|
|
|
|
|
|
|
|
43
|
7
|
|
|
7
|
|
227299
|
use HTTP::Tiny::UA::Response (); |
|
7
|
|
|
|
|
17740
|
|
|
7
|
|
|
|
|
107
|
|
44
|
|
|
|
|
|
|
|
45
|
7
|
|
|
7
|
|
2482
|
use Net::ACME::Constants (); |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
91
|
|
46
|
7
|
|
|
7
|
|
25
|
use Net::ACME::X (); |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
1405
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
our $VERSION; |
49
|
|
|
|
|
|
|
*VERSION = \$Net::ACME::Constants::VERSION; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#Use this to tweak SSL config, e.g., if you want to cache PublicSuffix. |
52
|
|
|
|
|
|
|
our @SSL_OPTIONS; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub new { |
55
|
12
|
|
|
12
|
1
|
32
|
my ( $class, %args ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$args{'SSL_options'} &&= { |
58
|
12
|
|
50
|
|
|
53
|
%{ $args{'SSL_options'} }, |
|
0
|
|
|
|
|
0
|
|
59
|
|
|
|
|
|
|
@SSL_OPTIONS, |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
12
|
|
|
|
|
109
|
my $self = $class->SUPER::new( |
63
|
|
|
|
|
|
|
verify_SSL => 1, |
64
|
|
|
|
|
|
|
%args, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
12
|
|
|
|
|
1193
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub request { |
71
|
13
|
|
|
13
|
1
|
28
|
my ( $self, $method, $url, $args_hr ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#HTTP::Tiny clobbers $@. The clobbering is useless since the |
74
|
|
|
|
|
|
|
#error is in the $resp variable already. Clobbering also risks |
75
|
|
|
|
|
|
|
#action-at-a-distance problems, so prevent it here. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#cf. eval_bug.readme |
78
|
13
|
|
|
|
|
17
|
my $eval_err = $@; |
79
|
|
|
|
|
|
|
|
80
|
13
|
|
66
|
|
|
287
|
my $resp = $self->SUPER::request( $method, $url, $args_hr || () ); |
81
|
|
|
|
|
|
|
|
82
|
13
|
|
|
|
|
1028459
|
$@ = $eval_err; |
83
|
|
|
|
|
|
|
|
84
|
13
|
|
|
|
|
162
|
my $resp_obj = HTTP::Tiny::UA::Response->new($resp); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#cf. HTTP::Tiny docs |
87
|
13
|
100
|
|
|
|
976
|
if ( $resp_obj->status() == 599 ) { |
88
|
|
|
|
|
|
|
die Net::ACME::X::create( |
89
|
|
|
|
|
|
|
'HTTP::Network', |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
method => $method, |
92
|
|
|
|
|
|
|
url => $url, |
93
|
|
|
|
|
|
|
error => $resp_obj->content(), |
94
|
1
|
|
|
|
|
23
|
redirects => $resp->{'redirects'}, |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
12
|
50
|
|
|
|
109
|
if ( $resp->{'status'} >= 400 ) { |
100
|
|
|
|
|
|
|
die Net::ACME::X::create( |
101
|
|
|
|
|
|
|
'HTTP::Protocol', |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
method => $method, |
104
|
|
|
|
|
|
|
redirects => $resp->{'redirects'}, |
105
|
0
|
|
|
|
|
0
|
( map { ( $_ => $resp_obj->$_() ) } qw( content status reason url headers ) ), |
|
0
|
|
|
|
|
0
|
|
106
|
|
|
|
|
|
|
}, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
12
|
|
|
|
|
65
|
return $resp_obj; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|