Skip to content

Commit 6684b93

Browse files
committed
Add --insecure to switch to http
1 parent 3efe8e2 commit 6684b93

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

App-cpanminus/script/cpanm.PL

+8-1
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,16 @@ Defaults to true (man pages generated) unless C<-L|--local-lib-contained>
555555
option is supplied in which case it's set to false. You can disable
556556
it with C<--no-man-pages>.
557557
558+
=item --insecure
559+
560+
By default, cpanm only uses HTTPS. If your environment lacks TLS
561+
support, you can consider at your own risk to use HTTP instead by
562+
using the C<--insecure> flag.
563+
Be aware that when using that argument all requests will use HTTP.
564+
558565
=item --lwp
559566
560-
Uses L<LWP> module to download stuff over HTTP. Defaults to true, and
567+
Uses L<LWP> module to download stuff over HTTPS. Defaults to true, and
561568
you can say C<--no-lwp> to disable using LWP, when you want to upgrade
562569
LWP from CPAN on some broken perl systems.
563570

Menlo-Legacy/lib/Menlo/CLI/Compat.pm

+21-9
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ sub new {
7979
try_lwp => 1,
8080
try_wget => 1,
8181
try_curl => 1,
82+
use_http => 0,
8283
uninstall_shadows => ($] < 5.012),
8384
skip_installed => 1,
8485
skip_satisfied => 0,
@@ -199,6 +200,7 @@ sub parse_options {
199200
'lwp!' => \$self->{try_lwp},
200201
'wget!' => \$self->{try_wget},
201202
'curl!' => \$self->{try_curl},
203+
'insecure!' => \$self->{use_http},
202204
'auto-cleanup=s' => \$self->{auto_cleanup},
203205
'man-pages!' => \$self->{pod2man},
204206
'scandeps' => \$self->{scandeps},
@@ -453,7 +455,7 @@ sub search_common {
453455
$self->chat("Found $found->{module} $found->{module_version} which doesn't satisfy $want_version.\n");
454456
}
455457
}
456-
458+
457459
return;
458460
}
459461

@@ -977,7 +979,7 @@ sub append_args {
977979
my($self, $cmd, $phase) = @_;
978980

979981
return $cmd if ref $cmd ne 'ARRAY';
980-
982+
981983
if (my $args = $self->{build_args}{$phase}) {
982984
$cmd = join ' ', Menlo::Util::shell_quote(@$cmd), $args;
983985
}
@@ -2657,6 +2659,10 @@ sub mirror {
26572659
return $self->file_mirror($uri, $local);
26582660
}
26592661

2662+
# HTTPTinyish does not provide an option to disable
2663+
# certificates check, let's switch to http on demand.
2664+
$uri =~ s/^https:/http:/ if $self->{use_http};
2665+
26602666
my $reply = $self->{http}->mirror($uri, $local);
26612667

26622668
if ( $uri =~ /^https:/ && ref $reply
@@ -2673,7 +2679,8 @@ sub mirror {
26732679
die <<"DIE";
26742680
TLS issue found while fetching $uri:\n
26752681
$reply->{content}\n
2676-
Please verify your certificates or force an HTTP-only request/mirror at your own risk.
2682+
Please verify your certificates or force an HTTP-only request/mirror
2683+
using --insecure option at your own risk.
26772684
DIE
26782685
}
26792686
}
@@ -2722,14 +2729,16 @@ sub configure_http {
27222729

27232730
require HTTP::Tinyish;
27242731

2732+
my $use_http = $self->{use_http};
2733+
27252734
my @try = qw(HTTPTiny);
27262735
unshift @try, 'Wget' if $self->{try_wget};
27272736
unshift @try, 'Curl' if $self->{try_curl};
27282737
unshift @try, 'LWP' if $self->{try_lwp};
27292738

2730-
my @protocol = ('https');
2739+
my @protocol = ( $use_http ? 'http' : 'https' );
27312740
push @protocol, 'http'
2732-
if grep /^http:/, @{$self->{mirrors}};
2741+
if !$use_http && grep /^http:/, @{$self->{mirrors}};
27332742

27342743
my $backend;
27352744
for my $try (map "HTTP::Tinyish::$_", @try) {
@@ -2745,11 +2754,14 @@ sub configure_http {
27452754
}
27462755
}
27472756

2748-
if ( !$backend ) {
2749-
$self->diag_fail( join( ', ', @protocol )." not supported by available HTTP Clients." );
2750-
}
2757+
# In case we use https protocol by default
2758+
# and then later we try to perform non https requests
2759+
# we still want these requests to succeed
2760+
# Note: this is disabling the client cache optimization above
2761+
# and will fail later for SSL requests as no clients support TLS
2762+
$backend ||= 'HTTP::Tinyish';
27512763

2752-
$backend->new(agent => "Menlo/$Menlo::VERSION", verify_SSL => 1);
2764+
$backend->new(agent => "Menlo/$Menlo::VERSION", $use_http ? () : ( verify_SSL => 1 ) );
27532765
}
27542766

27552767
sub init_tools {

0 commit comments

Comments
 (0)