user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] mbox: do not barf on queries which return no results
@ 2018-04-03 10:48 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2018-04-03 10:48 UTC (permalink / raw)
  To: meta

Having zero search results means we never get a chance
to populate the Content-Disposition header for mbox
downloads.
---
 lib/PublicInbox/Mbox.pm       | 7 ++++++-
 lib/PublicInbox/SearchView.pm | 1 +
 t/psgi_search.t               | 4 ++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 84cc384..04c86cc 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 219006a..1c4442e 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 84b3daa..cf5a7e9 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();
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-04-03 10:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-03 10:48 [PATCH] mbox: do not barf on queries which return no results Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).