1 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::TestCommon;
8 my ($tmpdir, $for_destroy) = tmpdir();
9 my $maindir = "$tmpdir/main.git";
10 my $addr = 'test-public@example.com';
11 my $cfgpfx = "publicinbox.test";
12 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape Plack::Builder);
13 require_mods(@mods, 'IO::Uncompress::Gunzip');
14 use_ok $_ foreach @mods;
15 use PublicInbox::Import;
17 use PublicInbox::Config;
18 use_ok 'PublicInbox::WWW';
19 use_ok 'PublicInbox::WwwText';
20 my $config = PublicInbox::Config->new(\<<EOF);
22 $cfgpfx.inboxdir=$maindir
24 PublicInbox::Import::init_bare($maindir);
25 my $www = PublicInbox::WWW->new($config);
27 test_psgi(sub { $www->call(@_) }, sub {
30 my $req = GET('/test/_/text/help/');
31 my $res = $cb->($req);
32 my $content = $res->content;
33 like($content, qr!<title>public-inbox help.*</title>!, 'default help');
34 $req->header('Accept-Encoding' => 'gzip');
36 is($res->header('Content-Encoding'), 'gzip', 'got gzip encoding');
37 is($res->header('Content-Type'), 'text/html; charset=UTF-8',
39 IO::Uncompress::Gunzip::gunzip(\($res->content) => \$gunzipped);
40 is($gunzipped, $content, 'gzipped content is correct');
42 $req = GET('/test/_/text/config/raw');
44 $content = $res->content;
45 my $olen = $res->header('Content-Length');
46 my $f = "$tmpdir/cfg";
47 open my $fh, '>', $f or die;
48 print $fh $content or die;
50 my $cfg = PublicInbox::Config->new($f);
51 is($cfg->{"$cfgpfx.address"}, $addr, 'got expected address in config');
53 $req->header('Accept-Encoding' => 'gzip');
55 is($res->header('Content-Encoding'), 'gzip', 'got gzip encoding');
56 ok($res->header('Content-Length') < $olen, 'gzipped help is smaller');
57 IO::Uncompress::Gunzip::gunzip(\($res->content) => \$gunzipped);
58 is($gunzipped, $content);