]> Sergey Matveev's repositories - public-inbox.git/commitdiff
mboxgz: ensure gzipped mboxes always have filenames
authorEric Wong <e@yhbt.net>
Thu, 30 Jan 2020 09:19:06 +0000 (09:19 +0000)
committerEric Wong <e@yhbt.net>
Fri, 31 Jan 2020 23:00:07 +0000 (23:00 +0000)
Lets always have Content-Disposition for files intended
to be downloaded for consumption by non-browsers, such
as pigz, zcat, "git am".

This is also to be consistent with the non-gzipped mbox
$MESSAGE_ID/raw endpoint.

lib/PublicInbox/MboxGz.pm
t/psgi_search.t

index 08e3c8464c4fb800fc075cd145d92ec16820a39e..30074e4dc2a73c7b50e28a9253d6fc53d125f9a6 100644 (file)
@@ -21,12 +21,10 @@ sub response {
        my ($class, $ctx, $cb, $fn) = @_;
        my $body = $class->new($ctx, $cb);
        # http://www.iana.org/assignments/media-types/application/gzip
-       my @h = qw(Content-Type application/gzip);
-       if (defined $fn && $fn ne '') {
-               $fn = to_filename($fn);
-               push @h, 'Content-Disposition', "inline; filename=$fn.mbox.gz";
-       }
-       [ 200, \@h, $body ];
+       $fn = defined($fn) && $fn ne '' ? to_filename($fn) : 'no-subject';
+       my $h = [ qw(Content-Type application/gzip),
+               'Content-Disposition', "inline; filename=$fn.mbox.gz" ];
+       [ 200, $h, $body ];
 }
 
 sub gzip_fail ($$) {
index 56b421189bf42c0b19391269607de1e68e98a0a4..4ff25eb2e9b6d0e617d1edf9e70b4816aabdf15b 100644 (file)
@@ -107,6 +107,12 @@ test_psgi(sub { $www->call(@_) }, sub {
                'subject-less message linked from "/$INBOX/?q=..."');
        like($html, qr/\bhref="blank-subject[^>]+>\(no subject\)</,
                'blank subject message linked from "/$INBOX/?q=..."');
+       $res = $cb->(GET('/test/no-subject-at-all@example.com/raw'));
+       like($res->header('Content-Disposition'),
+               qr/filename=no-subject\.txt/);
+       $res = $cb->(GET('/test/no-subject-at-all@example.com/t.mbox.gz'));
+       like($res->header('Content-Disposition'),
+               qr/filename=no-subject\.mbox\.gz/);
 });
 
 done_testing();