line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::ACME::RetryAfter; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
4
|
|
|
|
|
|
|
# A base class for modules that handle the 202 status with Retry-After |
5
|
|
|
|
|
|
|
# header, as described in the ACME protocol spec. |
6
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
1756
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
133
|
|
9
|
5
|
|
|
5
|
|
17
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
90
|
|
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
618
|
use Net::ACME::HTTP (); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
1251
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
8
|
|
|
8
|
0
|
2886
|
my ( $class, %opts ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
8
|
50
|
|
|
|
27
|
my $uri = $opts{'uri'} or do { |
17
|
0
|
|
|
|
|
0
|
die( sprintf "“%s” requires a “uri”!", __PACKAGE__ ); |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
|
|
21
|
my $self = bless { _uri => $uri }, $class; |
21
|
|
|
|
|
|
|
|
22
|
8
|
100
|
|
|
|
19
|
if ( $opts{'retry_after'} ) { |
23
|
4
|
|
|
|
|
16
|
$self->_consume_retry_after_value( $opts{'retry_after'} ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
|
|
18
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
0
|
17
|
sub uri { return (shift)->{'_uri'}; } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub is_time_to_poll { |
32
|
9
|
|
|
9
|
0
|
4001190
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
9
|
|
|
|
|
22
|
my $earliest_time = $self->{'_next_retry_time'}; |
35
|
|
|
|
|
|
|
|
36
|
9
|
100
|
100
|
|
|
87
|
return 1 if !$earliest_time || ( time >= $earliest_time ); |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
18
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub poll { |
42
|
10
|
|
|
10
|
0
|
855
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
10
|
|
|
|
|
39
|
my $resp = $self->_http_get( $self->{'_uri'} ); |
45
|
|
|
|
|
|
|
|
46
|
10
|
100
|
|
|
|
1245
|
if ( $resp->status() == 202 ) { |
47
|
3
|
|
|
|
|
44
|
$self->_consume_retry_after_value( $resp->header('retry-after') ); |
48
|
3
|
|
|
|
|
20
|
return undef; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
7
|
|
|
|
|
58
|
return scalar $self->_handle_non_202_poll($resp); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
#https://ietf-wg-acme.github.io/acme/#certificate-issuance |
55
|
|
|
|
|
|
|
sub _consume_retry_after_value { |
56
|
7
|
|
|
7
|
|
36
|
my ( $self, $val ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
7
|
|
33
|
|
|
48
|
$self->{'_next_retry_time'} = $val && ( time + $val ); |
59
|
|
|
|
|
|
|
|
60
|
7
|
|
|
|
|
10
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _http_get { |
64
|
10
|
|
|
10
|
|
13
|
my ( $self, $uri ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
10
|
|
66
|
|
|
69
|
$self->{'_http'} ||= Net::ACME::HTTP->new(); |
67
|
|
|
|
|
|
|
|
68
|
10
|
|
|
|
|
28
|
return $self->{'_http'}->get($uri); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |