From b26d31678a97a6a8581c1775acf956e7e4f5328c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 19 May 2024 21:55:09 +0000 Subject: [PATCH] www_text: fix /$INBOX/_/text/help/raw endpoint It wasn't ever documented, but since config/raw exists, it makes sense for help/raw to exist, too. --- lib/PublicInbox/WwwText.pm | 2 +- t/psgi_text.t | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index 5e23005e9..8279591a5 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -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); diff --git a/t/psgi_text.t b/t/psgi_text.t index 25599dd97..b8b1bc48a 100644 --- a/t/psgi_text.t +++ b/t/psgi_text.t @@ -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); }); -- 2.47.2