| 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
|
|
49
|
use strict; |
|
|
7
|
|
|
|
|
12
|
|
|
|
7
|
|
|
|
|
225
|
|
|
39
|
7
|
|
|
7
|
|
35
|
use warnings; |
|
|
7
|
|
|
|
|
13
|
|
|
|
7
|
|
|
|
|
197
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
7
|
|
|
7
|
|
36
|
use parent qw( HTTP::Tiny ); |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
36
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
7
|
|
|
7
|
|
324691
|
use HTTP::Tiny::UA::Response (); |
|
|
7
|
|
|
|
|
23426
|
|
|
|
7
|
|
|
|
|
157
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Circular dependency required because metacpan.org will (apparently?) |
|
46
|
|
|
|
|
|
|
# ignore distros that don’t define $VERSION in their main-indexed module. |
|
47
|
|
|
|
|
|
|
# This was not formerly the case … |
|
48
|
7
|
|
|
7
|
|
2546
|
use Net::ACME (); |
|
|
7
|
|
|
|
|
25
|
|
|
|
7
|
|
|
|
|
141
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
7
|
|
|
7
|
|
47
|
use Net::ACME::X (); |
|
|
7
|
|
|
|
|
18
|
|
|
|
7
|
|
|
|
|
1914
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#Use this to tweak SSL config, e.g., if you want to cache PublicSuffix. |
|
53
|
|
|
|
|
|
|
our @SSL_OPTIONS; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
|
56
|
12
|
|
|
12
|
1
|
56
|
my ( $class, %args ) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$args{'SSL_options'} = { |
|
59
|
12
|
50
|
|
|
|
71
|
( $args{'SSL_options'} ? (%{ $args{'SSL_options'} }) : () ), |
|
|
0
|
|
|
|
|
0
|
|
|
60
|
|
|
|
|
|
|
@SSL_OPTIONS, |
|
61
|
|
|
|
|
|
|
}; |
|
62
|
|
|
|
|
|
|
|
|
63
|
12
|
|
|
|
|
133
|
my $self = $class->SUPER::new( |
|
64
|
|
|
|
|
|
|
verify_SSL => 1, |
|
65
|
|
|
|
|
|
|
%args, |
|
66
|
|
|
|
|
|
|
); |
|
67
|
|
|
|
|
|
|
|
|
68
|
12
|
|
|
|
|
44
|
return $self; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub request { |
|
72
|
13
|
|
|
13
|
1
|
48
|
my ( $self, $method, $url, $args_hr ) = @_; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#HTTP::Tiny clobbers $@. The clobbering is useless since the |
|
75
|
|
|
|
|
|
|
#error is in the $resp variable already. Clobbering also risks |
|
76
|
|
|
|
|
|
|
#action-at-a-distance problems, so prevent it here. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#cf. eval_bug.readme |
|
79
|
13
|
|
|
|
|
33
|
my $eval_err = $@; |
|
80
|
|
|
|
|
|
|
|
|
81
|
13
|
|
66
|
|
|
334
|
my $resp = $self->SUPER::request( $method, $url, $args_hr || () ); |
|
82
|
|
|
|
|
|
|
|
|
83
|
13
|
|
|
|
|
2014031
|
$@ = $eval_err; |
|
84
|
|
|
|
|
|
|
|
|
85
|
13
|
|
|
|
|
220
|
my $resp_obj = HTTP::Tiny::UA::Response->new($resp); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#cf. HTTP::Tiny docs |
|
88
|
13
|
100
|
|
|
|
1343
|
if ( $resp_obj->status() == 599 ) { |
|
89
|
|
|
|
|
|
|
die Net::ACME::X::create( |
|
90
|
|
|
|
|
|
|
'HTTP::Network', |
|
91
|
|
|
|
|
|
|
{ |
|
92
|
|
|
|
|
|
|
method => $method, |
|
93
|
|
|
|
|
|
|
url => $url, |
|
94
|
|
|
|
|
|
|
error => $resp_obj->content(), |
|
95
|
1
|
|
|
|
|
31
|
redirects => $resp->{'redirects'}, |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
12
|
50
|
|
|
|
148
|
if ( $resp->{'status'} >= 400 ) { |
|
101
|
|
|
|
|
|
|
die Net::ACME::X::create( |
|
102
|
|
|
|
|
|
|
'HTTP::Protocol', |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
|
|
|
|
|
|
method => $method, |
|
105
|
|
|
|
|
|
|
redirects => $resp->{'redirects'}, |
|
106
|
0
|
|
|
|
|
0
|
( map { ( $_ => $resp_obj->$_() ) } qw( content status reason url headers ) ), |
|
|
0
|
|
|
|
|
0
|
|
|
107
|
|
|
|
|
|
|
}, |
|
108
|
|
|
|
|
|
|
); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
12
|
|
|
|
|
81
|
return $resp_obj; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
12
|
|
|
12
|
0
|
761
|
sub VERSION { $Net::ACME::VERSION } |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |