| 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<HTTP::Tiny::UA>, just without the | ||||||||||||||||||||
| 27 | dependency on C<superclass.pm> (which brings in a mess of other undesirables). | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | The chief benefit is that C<request()> and related methods will return | ||||||||||||||||||||
| 30 | instances of C<HTTP::Tiny::UA::Response> rather than simple hashes. | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | This also always verifies remote SSL connections and always C<die()>s if | ||||||||||||||||||||
| 33 | either the network connection fails or the protocol indicates an error | ||||||||||||||||||||
| 34 | (4xx or 5xx). | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 7 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | 7 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 7 | ▶ | use parent qw( HTTP::Tiny ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 7 | ▶ | use HTTP::Tiny::UA::Response (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 7 | ▶ | use Net::ACME::Constants (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | 7 | ▶ | use Net::ACME::X (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 7 | our $VERSION; | |||||||||||||||||||
| 49 | 7 | *VERSION = \$Net::ACME::Constants::VERSION; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 7 | ▶ | use constant VERSION => $Net::ACME::Constants::VERSION; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | #Use this to tweak SSL config, e.g., if you want to cache PublicSuffix. | ||||||||||||||||||||
| 54 | 7 | our @SSL_OPTIONS; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | sub new { | ||||||||||||||||||||
| 57 | 12 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | $args{'SSL_options'} = { | ||||||||||||||||||||
| 60 | 12 | ▶ | ( $args{'SSL_options'} ? (%{ $args{'SSL_options'} }) : () ), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | @SSL_OPTIONS, | ||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 12 | my $self = $class->SUPER::new( | |||||||||||||||||||
| 65 | verify_SSL => 1, | ||||||||||||||||||||
| 66 | %args, | ||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 12 | return $self; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | sub request { | ||||||||||||||||||||
| 73 | 13 | ▶ | my ( $self, $method, $url, $args_hr ) = @_; | ||||||||||||||||||
|
Subroutine
request: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | #HTTP::Tiny clobbers $@. The clobbering is useless since the | ||||||||||||||||||||
| 76 | #error is in the $resp variable already. Clobbering also risks | ||||||||||||||||||||
| 77 | #action-at-a-distance problems, so prevent it here. | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | #cf. eval_bug.readme | ||||||||||||||||||||
| 80 | 13 | my $eval_err = $@; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 13 | ▶ | my $resp = $self->SUPER::request( $method, $url, $args_hr || () ); | ||||||||||||||||||
|
Condition66%2/3
$args_hr || ()
MC/DC0%0/2
$args_hr || ()
$args_hr
()
Truth table66%2/3
A || B
A= $args_hrB= ()
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 13 | $@ = $eval_err; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 13 | my $resp_obj = HTTP::Tiny::UA::Response->new($resp); | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | #cf. HTTP::Tiny docs | ||||||||||||||||||||
| 89 | 13 | ▶ | if ( $resp_obj->status() == 599 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | die Net::ACME::X::create( | ||||||||||||||||||||
| 91 | 'HTTP::Network', | ||||||||||||||||||||
| 92 | { | ||||||||||||||||||||
| 93 | method => $method, | ||||||||||||||||||||
| 94 | url => $url, | ||||||||||||||||||||
| 95 | error => $resp_obj->content(), | ||||||||||||||||||||
| 96 | 1 | redirects => $resp->{'redirects'}, | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 12 | ▶ | if ( $resp->{'status'} >= 400 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | die Net::ACME::X::create( | ||||||||||||||||||||
| 103 | 'HTTP::Protocol', | ||||||||||||||||||||
| 104 | { | ||||||||||||||||||||
| 105 | method => $method, | ||||||||||||||||||||
| 106 | redirects => $resp->{'redirects'}, | ||||||||||||||||||||
| 107 | 0 | ( map { ( $_ => $resp_obj->$_() ) } qw( content status reason url headers ) ), | |||||||||||||||||||
| 108 | }, | ||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 12 | return $resp_obj; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 7 | 1; | |||||||||||||||||||
| 116 | |||||||||||||||||||||