From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id DFCBF1F570 for ; Sun, 19 May 2024 21:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1716155711; bh=DkyVYmkKm2Fo5Pm+Jcycxupohq0mHhI8n3jp4g1r2es=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pBy5yaiI/E80GFnoRTqu/Ksg5exduEshMjBhmyYO+0/90GVEa4WZaZxp2vZGyYTq6 quXVonpWjdEOyhnSeuTgc7CNoPMe1stVT5i2ggHp0y2XGiZVZdTj4+MRIEK37K7I+0 t8T7SuJKoN+CxFISDOjNChL045hCm3zY+/oqaDTc= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 9/9] www_text: fix /$INBOX/_/text/help/raw endpoint Date: Sun, 19 May 2024 21:55:09 +0000 Message-Id: <20240519215509.2267117-10-e@80x24.org> In-Reply-To: <20240519215509.2267117-1-e@80x24.org> References: <20240519215509.2267117-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 5e23005e..8279591a 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 25599dd9..b8b1bc48 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); });