about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/PublicInbox/Mbox.pm7
-rw-r--r--lib/PublicInbox/SearchView.pm1
-rw-r--r--t/psgi_search.t4
3 files changed, 11 insertions, 1 deletions
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 84cc3845..04c86cc1 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -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 ];
 }
 
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 219006a0..1c4442e4 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -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);
 }
diff --git a/t/psgi_search.t b/t/psgi_search.t
index 84b3daa3..cf5a7e91 100644
--- a/t/psgi_search.t
+++ b/t/psgi_search.t
@@ -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();