File Coverage

blib/lib/LWP/Protocol/connect.pm
Criterion Covered Total %
statement 6 23 26.0
branch 0 6 0.0
condition n/a
subroutine 2 3 66.6
pod 1 1 100.0
total 9 33 27.2


line stmt bran cond sub pod time code
1             package LWP::Protocol::connect;
2              
3 1     1   920 use warnings;
  1         2  
  1         38  
4 1     1   4 use strict;
  1         2  
  1         525  
5              
6             our $VERSION = '6.09'; # VERSION
7              
8             require LWP::Protocol;
9             our @ISA = qw(LWP::Protocol);
10              
11             our @supported_schemes = ( 'https', 'http' );
12              
13             sub request {
14 0     0 1   my($self, $request, $proxy, $arg, $size, $timeout) = @_;
15 0           my $url = $request->uri;
16 0           my $scheme = $url->scheme;
17              
18 0 0         if(!defined $proxy) {
19 0           return HTTP::Response->new( &HTTP::Status::RC_BAD_REQUEST,
20             'HTTP/CONNECT method protocol schema can only be used with a proxy!');
21             }
22              
23 0 0         if( ! grep { $scheme eq $_ } @supported_schemes ) {
  0            
24 0           return HTTP::Response->new( &HTTP::Status::RC_BAD_REQUEST,
25             $scheme.' protocol scheme is not supported by '. __PACKAGE__ );
26             }
27              
28 0           my $connect_scheme = $scheme."::connect";
29 0           my $socket_scheme = $connect_scheme."::Socket";
30              
31 0           for my $scheme ( $connect_scheme, $socket_scheme ) {
32 0           eval 'require LWP::Protocol::'.$scheme; ## no critic
33 0 0         if( $@ ) {
34 0           return HTTP::Response->new( &HTTP::Status::RC_BAD_REQUEST,
35             'could not load '.$connect_scheme.' protocol support: '.$@);
36             }
37             }
38              
39 0           my $protocol = LWP::Protocol::create($connect_scheme, $self->{ua});
40 0           $protocol->{proxy_connect_opts} = [
41             ProxyAddr => $proxy->host,
42             ProxyPort => $proxy->port,
43             ProxyUserinfo => $proxy->userinfo,
44             Agent => $self->{ua},
45             ];
46              
47 0           $protocol->request($request, undef, $arg, $size, $timeout);
48             }
49              
50             1;
51              
52             __END__