]> Sergey Matveev's repositories - public-inbox.git/commitdiff
mbox: do not barf on queries which return no results
authorEric Wong <e@80x24.org>
Tue, 3 Apr 2018 10:34:54 +0000 (10:34 +0000)
committerEric Wong <e@80x24.org>
Tue, 3 Apr 2018 10:48:05 +0000 (10:48 +0000)
Having zero search results means we never get a chance
to populate the Content-Disposition header for mbox
downloads.

lib/PublicInbox/Mbox.pm
lib/PublicInbox/SearchView.pm
t/psgi_search.t

index 84cc384529f174cd020bbfb2360519720b5d0929..04c86cc196515e345d36491b200a1d29f3e4bd17 100644 (file)
@@ -157,7 +157,12 @@ sub response {
        # http://www.iana.org/assignments/media-types/application/gzip
        $body->{hdr} = [ 'Content-Type', 'application/gzip' ];
        $body->{fn} = $fn;
-       my $hdr = $body->getline; # fill in Content-Disposition filename
+       # fill in Content-Disposition filename
+       my $hdr = $body->getline;
+       if ($body->{hdr}) {
+               return [ 404, ['Content-Type','text/plain'],
+                       [ "No results found\n" ] ];
+       }
        [ 200, $hdr, $body ];
 }
 
index 219006a0d7070dbfc58530255eba7aeba1919ff4..1c4442e4d7b8a300775c817aac435b47da9abb56 100644 (file)
@@ -22,6 +22,7 @@ sub mbox_results {
        my ($ctx) = @_;
        my $q = PublicInbox::SearchQuery->new($ctx->{qp});
        my $x = $q->{x};
+       require PublicInbox::Mbox;
        return PublicInbox::Mbox::mbox_all($ctx, $q->{'q'}) if $x eq 'm';
        sres_top_html($ctx);
 }
index 84b3daa3402ac071b4562addc70ef3e6e547e71d..cf5a7e91b04de15ec9e77d82ac4824a8d03c57a4 100644 (file)
@@ -70,6 +70,10 @@ test_psgi(sub { $www->call(@_) }, sub {
        $res = $cb->(GET('/test/?q=s:test&l=5e'));
        is($res->code, 200, 'successful search result');
        is_deeply([], $warn, 'no warnings from non-numeric comparison');
+
+       $res = $cb->(POST('/test/?q=s:bogus&x=m'));
+       is($res->code, 404, 'failed search result gives 404');
+       is_deeply([], $warn, 'no warnings');
 });
 
 done_testing();