| 1 | package Plient::Handler::HTTPLite; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | require Plient::Handler unless $Plient::bundle_mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | our @ISA = 'Plient::Handler'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | my ( $HTTPLite, %all_protocol, %protocol, %method ); | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | %all_protocol = ( http => undef ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub all_protocol { return \%all_protocol } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_protocol: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub protocol { return \%protocol } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
protocol: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub method { return \%method } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
method: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub support_method { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
support_method: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my ( $method, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if ( $args | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$args and $args->{"content_type"} and $args->{"content_type"} =~ /form-data/
$args and $args->{"content_type"}
MC/DC0%0/3
$args and $args->{"content_type"} and $args->{"content_type"} =~ /form-data/
$args
$args->{"content_type"}
$args->{"content_type"} =~ /form-data/
Truth table0%0/4
A and B and C
A= $argsB= $args->{"content_type"}C= $args->{"content_type"} =~ /form-data/
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | && $args->{content_type} | ||||||||||||||||||||||||||||||||||||||||||
| 19 | && $args->{content_type} =~ 'form-data' ) | ||||||||||||||||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ( $ENV{http_proxy} && $ENV{http_proxy} =~ /@/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"http_proxy"} and $ENV{"http_proxy"} =~ /@/
MC/DC0%0/2
$ENV{"http_proxy"} and $ENV{"http_proxy"} =~ /@/
$ENV{"http_proxy"}
$ENV{"http_proxy"} =~ /@/
Truth table0%0/3
A and B
A= $ENV{"http_proxy"}B= $ENV{"http_proxy"} =~ /@/
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | # HTTPLite doesn't support proxy auth | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return $class->SUPER::support_method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | my $inited; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return if $inited; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $inited = 1; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | eval { require HTTP::Lite } or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | undef $protocol{http}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $method{http_get} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my ( $uri, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $http = HTTP::Lite->new; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | add_headers( $http, $uri, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $http->proxy( $ENV{http_proxy} ) if $ENV{http_proxy}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $res = $http->request($uri) || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$http->request($uri) || ''
MC/DC0%0/1
$http->request($uri) || ''
$http->request($uri)
Truth table0%0/2
A
A= $http->request($uri)
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( $res == 200 || $res == 301 || $res == 302 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$res == 200 or $res == 301 or $res == 302
$res == 200 or $res == 301
MC/DC0%0/3
$res == 200 or $res == 301 or $res == 302
$res == 200
$res == 301
$res == 302
Truth table0%0/4
A or B or C
A= $res == 200B= $res == 301C= $res == 302
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # XXX TODO handle redirect | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return $http->body; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | warn "failed to get $uri with HTTP::Lite: " . $res; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $method{http_post} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my ( $uri, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $http = HTTP::Lite->new; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $http->proxy( $ENV{http_proxy} ) if $ENV{http_proxy}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | add_headers( $http, $uri, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $http->prepare_post( $args->{body_hash} ) if $args->{body_hash}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $res = $http->request($uri) || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$http->request($uri) || ''
MC/DC0%0/1
$http->request($uri) || ''
$http->request($uri)
Truth table0%0/2
A
A= $http->request($uri)
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( $res == 200 || $res == 301 || $res == 302 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$res == 200 or $res == 301 or $res == 302
$res == 200 or $res == 301
MC/DC0%0/3
$res == 200 or $res == 301 or $res == 302
$res == 200
$res == 301
$res == 302
Truth table0%0/4
A or B or C
A= $res == 200B= $res == 301C= $res == 302
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # XXX TODO handle redirect | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return $http->body; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | warn "failed to post $uri with HTTP::Lite: " . $res; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub add_headers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_headers: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my ( $http, $uri, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $headers = $args->{headers} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'headers'} || {}
MC/DC0%0/1
$args->{'headers'} || {}
$args->{'headers'}
Truth table0%0/2
A
A= $args->{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | for my $k ( keys %$headers ) { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $http->add_req_header( $k, $headers->{$k} ); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( $args->{user} && defined $args->{password} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"user"} and defined $args->{"password"}
MC/DC0%0/2
$args->{"user"} and defined $args->{"password"}
$args->{"user"}
defined $args->{"password"}
Truth table0%0/3
A and B
A= $args->{"user"}B= defined $args->{"password"}
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $method = lc $args->{auth_method} || 'basic'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
lc $args->{'auth_method'} || 'basic'
MC/DC0%0/1
lc $args->{'auth_method'} || 'basic'
lc $args->{'auth_method'}
Truth table0%0/2
A
A= lc $args->{'auth_method'}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( $method eq 'basic' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $http->add_req_header( "Authorization", | |||||||||||||||||||||||||||||||||||||||||
| 89 | 'Basic ' | ||||||||||||||||||||||||||||||||||||||||||
| 90 | . MIME::Base64::encode_base64( "$args->{user}:$args->{password}", '' ) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | die "aborting: unsupported auth method: $method"; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | ▶ | __PACKAGE__->_add_to_plient if $Plient::bundle_mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||||||||||||||||