user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 2/2] mboxgz: ensure gzipped mboxes always have filenames
Date: Thu, 30 Jan 2020 09:19:06 +0000
Message-ID: <20200130091906.23882-3-e@yhbt.net> (raw)
In-Reply-To: <20200130091906.23882-1-e@yhbt.net>

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 | 10 ++++------
 t/psgi_search.t           |  6 ++++++
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/MboxGz.pm b/lib/PublicInbox/MboxGz.pm
index 08e3c846..30074e4d 100644
--- a/lib/PublicInbox/MboxGz.pm
+++ b/lib/PublicInbox/MboxGz.pm
@@ -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 ($$) {
diff --git a/t/psgi_search.t b/t/psgi_search.t
index 56b42118..4ff25eb2 100644
--- a/t/psgi_search.t
+++ b/t/psgi_search.t
@@ -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();

      parent reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30  9:19 [PATCH 0/2] subject-free tests and updates Eric Wong
2020-01-30  9:19 ` [PATCH 1/2] t/psgi_search: test for subject-free messages Eric Wong
2020-01-30  9:19 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200130091906.23882-3-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git