about summary refs log tree commit homepage
path: root/t/psgi_v2.t
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-07-05 23:27:32 +0000
committerEric Wong <e@yhbt.net>2020-07-06 20:01:15 +0000
commit903c74de0b1feae03fdeb8a7ce68b6327699e3a2 (patch)
tree30f223d9023d021e9f693d8100d74f490fcff8d3 /t/psgi_v2.t
parentbd0cddda0121bc80247b00a0797453fcdeba7e4c (diff)
downloadpublic-inbox-903c74de0b1feae03fdeb8a7ce68b6327699e3a2.tar.gz
This restores gzip-by-default behavior for /$INBOX/$MSGID/raw
endpoints for all indexed inboxes.  Unindexed v1 inboxes will
remain uncompressed, for now.
Diffstat (limited to 't/psgi_v2.t')
-rw-r--r--t/psgi_v2.t46
1 files changed, 40 insertions, 6 deletions
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 8f75a3fb..90a710a4 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -103,7 +103,7 @@ $mids = mids($mime->header_obj);
 my $third = $mids->[-1];
 $im->done;
 
-test_psgi(sub { $www->call(@_) }, sub {
+my $client = sub {
         my ($cb) = @_;
         $res = $cb->(GET("/v2test/$third/raw"));
         $raw = $res->content;
@@ -122,12 +122,19 @@ test_psgi(sub { $www->call(@_) }, sub {
 
         SKIP: {
                 eval { require IO::Uncompress::Gunzip };
-                skip 'IO::Uncompress::Gunzip missing', 4 if $@;
+                skip 'IO::Uncompress::Gunzip missing', 6 if $@;
+                my ($in, $out, $status);
+                my $req = GET('/v2test/a-mid@b/raw');
+                $req->header('Accept-Encoding' => 'gzip');
+                $res = $cb->($req);
+                is($res->header('Content-Encoding'), 'gzip', 'gzip encoding');
+                $in = $res->content;
+                IO::Uncompress::Gunzip::gunzip(\$in => \$out);
+                is($out, $raw, 'gzip response matches');
 
                 $res = $cb->(GET('/v2test/a-mid@b/t.mbox.gz'));
-                my $out;
-                my $in = $res->content;
-                my $status = IO::Uncompress::Gunzip::gunzip(\$in => \$out);
+                $in = $res->content;
+                $status = IO::Uncompress::Gunzip::gunzip(\$in => \$out);
                 unlike($out, qr/^From oldbug/sm, 'buggy "From_" line omitted');
                 like($out, qr/^hello world$/m, 'got first in t.mbox.gz');
                 like($out, qr/^hello world!$/m, 'got second in t.mbox.gz');
@@ -187,7 +194,34 @@ test_psgi(sub { $www->call(@_) }, sub {
                 like($raw, qr!>\Q$mid\E</a>!s, "Message-ID $mid shown");
         }
         like($raw, qr/\b3\+ messages\b/, 'thread overview shown');
+};
 
+test_psgi(sub { $www->call(@_) }, $client);
+SKIP: {
+        require_mods(qw(Plack::Test::ExternalServer), 37);
+        my $cfgpath = "$inboxdir/$$.config";
+        open my $fh, '>', $cfgpath or BAIL_OUT $!;
+        print $fh <<EOF or BAIL_OUT $!;
+[publicinbox "v2test"]
+        inboxdir = $inboxdir
+        address = test\@example.com
+EOF
+        close $fh or BAIL_OUT $!;
+        my $env = { PI_CONFIG => $cfgpath };
+        my $sock = tcp_server() or die;
+        my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
+        my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
+        my $td = start_script($cmd, $env, { 3 => $sock });
+        my ($h, $p) = ($sock->sockhost, $sock->sockport);
+        local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
+        Plack::Test::ExternalServer::test_psgi(client => $client);
+        $td->join('TERM');
+        open $fh, '<', $err or BAIL_OUT $!;
+        is(do { local $/; <$fh> }, '', 'no errors');
+};
+
+test_psgi(sub { $www->call(@_) }, sub {
+        my ($cb) = @_;
         my $exp = [ qw(<a-mid@b> <reuse@mid>) ];
         $mime->header_set('Message-Id', @$exp);
         $mime->header_set('Subject', '4th dupe');
@@ -208,7 +242,7 @@ test_psgi(sub { $www->call(@_) }, sub {
         $res = $cb->(GET('/v2test/reuse@mid/T/'));
         $raw = $res->content;
         like($raw, qr/\b4\+ messages\b/, 'thread overview shown with /T/');
-        @over = ($raw =~ m/^\d{4}-\d+-\d+\s+\d+:\d+ (.+)$/gm);
+        my @over = ($raw =~ m/^\d{4}-\d+-\d+\s+\d+:\d+ (.+)$/gm);
         is_deeply(\@over, [ '<a', '` <a', '` <a', '` <a' ],
                 'duplicate messages share the same root');