View | Details | Raw Unified | Return to bug 41929
Collapse All | Expand All

(-)a/Koha/UploadedFile.pm (-2 / +12 lines)
Lines 129-143 Will be extended by report 14282 Link Here
129
129
130
sub httpheaders {
130
sub httpheaders {
131
    my ($self) = @_;
131
    my ($self) = @_;
132
    my $cache_control;
133
    if ( $self->public ) {
134
135
        # 43200 = 12 hours, as defined in apache-shared.conf
136
        $cache_control = 'public, max-age=43200';
137
    } else {
138
        $cache_control = 'no-cache, no-store, max-age=0';
139
    }
132
    if ( $self->filename =~ /\.pdf$/ ) {
140
    if ( $self->filename =~ /\.pdf$/ ) {
133
        return (
141
        return (
134
            '-type'               => 'application/pdf',
142
            '-type'               => 'application/pdf',
143
            'Cache-Control'       => $cache_control,
135
            'Content-Disposition' => 'inline; filename="' . $self->filename . '"',
144
            'Content-Disposition' => 'inline; filename="' . $self->filename . '"',
136
        );
145
        );
137
    } else {
146
    } else {
138
        return (
147
        return (
139
            '-type'       => 'application/octet-stream',
148
            '-type'         => 'application/octet-stream',
140
            '-attachment' => $self->filename,
149
            '-attachment'   => $self->filename,
150
            'Cache-Control' => $cache_control,
141
        );
151
        );
142
    }
152
    }
143
}
153
}
(-)a/t/db_dependent/Upload.t (-11 / +26 lines)
Lines 255-261 subtest 'Simple tests for httpheaders and getCategories' => sub { Link Here
255
255
256
    my $rec  = Koha::UploadedFiles->search_term( { term => 'file' } )->next;
256
    my $rec  = Koha::UploadedFiles->search_term( { term => 'file' } )->next;
257
    my @hdrs = $rec->httpheaders;
257
    my @hdrs = $rec->httpheaders;
258
    is( @hdrs == 4 && $hdrs[1] =~ /application\/octet-stream/, 1, 'Simple test for httpheaders' );
258
    is( @hdrs == 6 && $hdrs[1] =~ /application\/octet-stream/, 1, 'Simple test for httpheaders' );
259
    $builder->build(
259
    $builder->build(
260
        {
260
        {
261
            source => 'AuthorisedValue',
261
            source => 'AuthorisedValue',
Lines 364-378 subtest 'Testing delete_temporary' => sub { Link Here
364
};
364
};
365
365
366
subtest 'Testing download headers' => sub {
366
subtest 'Testing download headers' => sub {
367
    plan tests => 2;
367
    plan tests => 3;
368
    my $test_pdf   = Koha::UploadedFile->new( { filename => 'pdf.pdf', uploadcategorycode => 'B', filesize => 1000 } );
368
    my $test_pdf =
369
    my $test_not   = Koha::UploadedFile->new( { filename => 'pdf.not', uploadcategorycode => 'B', filesize => 1000 } );
369
        Koha::UploadedFile->new( { filename => 'pdf.pdf', uploadcategorycode => 'B', filesize => 1000, public => 0 } );
370
    my @pdf_expect = ( '-type' => 'application/pdf',          'Content-Disposition' => 'inline; filename="pdf.pdf"' );
370
    my $test_not =
371
    my @not_expect = ( '-type' => 'application/octet-stream', '-attachment'         => 'pdf.not' );
371
        Koha::UploadedFile->new( { filename => 'pdf.not', uploadcategorycode => 'B', filesize => 1000, public => 0 } );
372
    my @pdf_head   = $test_pdf->httpheaders;
372
    my $test_public =
373
    my @not_head   = $test_not->httpheaders;
373
        Koha::UploadedFile->new( { filename => 'pdf.not', uploadcategorycode => 'B', filesize => 1000, public => 1 } );
374
    is_deeply( \@pdf_head, \@pdf_expect, "Get inline pdf headers for pdf" );
374
    my @pdf_expect = (
375
    is_deeply( \@not_head, \@not_expect, "Get download headers for non pdf" );
375
        '-type'               => 'application/pdf', 'Cache-Control' => 'no-cache, no-store, max-age=0',
376
        'Content-Disposition' => 'inline; filename="pdf.pdf"'
377
    );
378
    my @not_expect = (
379
        '-type'         => 'application/octet-stream', '-attachment' => 'pdf.not',
380
        'Cache-Control' => 'no-cache, no-store, max-age=0'
381
    );
382
    my @public_expect = (
383
        '-type'         => 'application/octet-stream', '-attachment' => 'pdf.not',
384
        'Cache-Control' => 'public, max-age=43200'
385
    );
386
    my @pdf_head    = $test_pdf->httpheaders;
387
    my @not_head    = $test_not->httpheaders;
388
    my @public_head = $test_public->httpheaders;
389
    is_deeply( \@pdf_head,    \@pdf_expect,    "Get inline pdf headers for pdf" );
390
    is_deeply( \@not_head,    \@not_expect,    "Get download headers for non pdf" );
391
    is_deeply( \@public_head, \@public_expect, "Get download headers for public file" );
376
};
392
};
377
393
378
# The end
394
# The end
379
- 

Return to bug 41929