]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www_text: fix /$INBOX/_/text/help/raw endpoint
authorEric Wong <e@80x24.org>
Sun, 19 May 2024 21:55:09 +0000 (21:55 +0000)
committerEric Wong <e@80x24.org>
Mon, 20 May 2024 18:29:48 +0000 (18:29 +0000)
It wasn't ever documented, but since config/raw exists, it makes
sense for help/raw to exist, too.

lib/PublicInbox/WwwText.pm
t/psgi_text.t

index 5e23005e964d3ade0f5786120a878a8fabee7360..8279591a5f929b496532d8d5518015a3b164a78d 100644 (file)
@@ -37,7 +37,7 @@ sub get_text {
        }
        my $env = $ctx->{env};
        if ($raw) {
-               my $h = delete $ctx->{-res_hdr};
+               my $h = delete $ctx->{-res_hdr} // [];
                $txt = gzf_maybe($h, $env)->zflush($txt) if $code == 200;
                push @$h, 'Content-Type', 'text/plain',
                        'Content-Length', length($txt);
index 25599dd97db0006d7f072adeda8fc21b43569696..b8b1bc48a4802e9fc6026bf4c4d6808744574d38 100644 (file)
@@ -3,12 +3,12 @@
 use v5.12;
 use PublicInbox::Eml;
 use PublicInbox::TestCommon;
+use IO::Uncompress::Gunzip qw(gunzip);
 my ($tmpdir, $for_destroy) = tmpdir();
 my $maindir = "$tmpdir/main.git";
 my $addr = 'test-public@example.com';
 my $cfgpfx = "publicinbox.test";
 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape Plack::Builder);
-require_mods(@mods, 'IO::Uncompress::Gunzip');
 use_ok $_ foreach @mods;
 use PublicInbox::Import;
 use_ok 'PublicInbox::WWW';
@@ -33,9 +33,24 @@ test_psgi(sub { $www->call(@_) }, sub {
        is($res->header('Content-Encoding'), 'gzip', 'got gzip encoding');
        is($res->header('Content-Type'), 'text/html; charset=UTF-8',
                'got gzipped HTML');
-       IO::Uncompress::Gunzip::gunzip(\($res->content) => \$gunzipped);
+       gunzip(\($res->content) => \$gunzipped);
        is($gunzipped, $content, 'gzipped content is correct');
 
+       $req = GET('/test/_/text/help/raw');
+       $res = $cb->($req);
+       like $res->header('Content-Type'), qr!\Atext/plain\b!,
+               'got text/plain Content-Type';
+       $content = $res->content;
+       like $content, qr!public-inbox help!, 'default help';
+
+       $req->header('Accept-Encoding' => 'gzip');
+       $res = $cb->($req);
+       is($res->header('Content-Encoding'), 'gzip', 'got gzip encoding');
+       like $res->header('Content-Type'), qr!\Atext/plain\b!,
+               'got text/plain Content-Type w/ gzip';
+       gunzip(\($res->content) => \$gunzipped);
+       is $gunzipped, $content, 'gzipped content is correct';
+
        $req = GET('/test/_/text/config/raw');
        $res = $cb->($req);
        $content = $res->content;
@@ -47,7 +62,7 @@ test_psgi(sub { $www->call(@_) }, sub {
        $res = $cb->($req);
        is($res->header('Content-Encoding'), 'gzip', 'got gzip encoding');
        ok($res->header('Content-Length') < $olen, 'gzipped help is smaller');
-       IO::Uncompress::Gunzip::gunzip(\($res->content) => \$gunzipped);
+       gunzip(\($res->content) => \$gunzipped);
        is($gunzipped, $content);
 });