return $retval;
}
+=head2 httpheaders
+
+ httpheaders returns http headers for a retrievable upload
+ Will be extended by report 14282
+
+=cut
+
+sub httpheaders {
+ my $file= shift;
+ return
+ ( '-type' => 'application/octet-stream',
+ '-attachment' => $file, );
+}
+
1;
my $id = $input->param('id');
my $file = C4::UploadedFiles::GetUploadedFile($id);
-exit 1 if not $file;
+exit 1 if !$file || !-f $file->{filepath};
-my $file_path = $file->{filepath};
-
-if( -f $file_path ) {
- open my $fh, '<', $file_path or die "Can't open file: $!";
- print $input->header(
- -type => "application/octet-stream",
- -attachment => $file->{filename}
- );
- while(<$fh>) {
- print $_;
- }
-} else {
- exit 1;
+open my $fh, '<', $file->{filepath} or die "Can't open file: $!";
+print $input->header( C4::UploadedFiles::httpheaders( $file->{filename} ));
+while(<$fh>) {
+ print $_;
}
-
-exit 0;
+close $fh;
use Modern::Perl;
use File::Temp qw/ tempdir /;
use Test::CGI::Multipart;
-use Test::More tests => 17;
+use Test::More tests => 18;
use Test::Warn;
use t::lib::Mocks;
warning_like { $UploadResult=C4::UploadedFiles::UploadFile($testfilename,'../',$testfile_fh->handle); } qr/^Filename or dirname contains '..'. Aborting upload/, "Expected warning for bad file upload.";
is($UploadResult, undef, "UploadFile with dir containing \"..\" return undef");
is(C4::UploadedFiles::GetUploadedFile(), undef, 'GetUploadedFile without parameters returns undef');
+
+#trivial test for httpheaders
+my @hdrs = C4::UploadedFiles::httpheaders('does_not_matter_yet');
+is( @hdrs == 4 && $hdrs[1] =~ /application\/octet-stream/, 1, 'Simple test for httpheaders'); #TODO Will be extended on report 14282