Skip to content

Commit

Permalink
Make file arg for mirror mandatory #304
Browse files Browse the repository at this point in the history
  • Loading branch information
simbabque authored and oalders committed Oct 10, 2019
1 parent afebadc commit bdd8ad9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/LWP/UserAgent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,8 @@ sub mirror
{
my($self, $url, $file) = @_;

die "Local file name is missing" unless $file;

my $request = HTTP::Request->new('GET', $url);

# If the file exists, add a cache-related header
Expand All @@ -979,10 +981,10 @@ sub mirror

my $response = $self->request($request, $tmpfile);
if ( $response->header('X-Died') ) {
die $response->header('X-Died');
die $response->header('X-Died');
}

# Only fetching a fresh copy of the would be considered success.
# Only fetching a fresh copy of the file would be considered success.
# If the file was not modified, "304" would returned, which
# is considered by HTTP::Status to be a "redirect", /not/ "success"
if ( $response->is_success ) {
Expand Down Expand Up @@ -1017,7 +1019,7 @@ sub mirror
}
# The local copy is fresh enough, so just delete the temp file
else {
unlink($tmpfile);
unlink($tmpfile);
}
return $response;
}
Expand Down
13 changes: 12 additions & 1 deletion t/local/http.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
use Test::Fatal;

use Config;
use FindBin qw($Bin);
Expand Down Expand Up @@ -62,7 +63,7 @@ sub _test {
return plan skip_all => 'We could not talk to our daemon' unless $DAEMON;
return plan skip_all => 'No base URI' unless $base;

plan tests => 90;
plan tests => 94;

my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/0.01 " . $ua->agent);
Expand Down Expand Up @@ -288,6 +289,16 @@ sub _test {
ok($res->is_success, 'post: is_success');
ok($res->content =~ /^Content-Type: multipart\/form-data; boundary=/m, 'post: multipart good');
}
{ # mirror
ok(exception { $ua->mirror(url("/echo/foo", $base)) }, 'mirror: filename required');
my $copy = "lwp-base-test-$$"; # downloaded copy
my $res = $ua->mirror(url("/echo/foo", $base), $copy);
isa_ok($res, 'HTTP::Response', 'mirror: good response object');
ok($res->is_success, 'mirror: is_success');

ok(-s $copy, 'mirror: file exists and is not empty');
unlink($copy);
}
{ # partial
my $req = HTTP::Request->new( GET => url("/partial", $base) );
my $res = $ua->request($req);
Expand Down

0 comments on commit bdd8ad9

Please sign in to comment.