2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use PublicInbox::Config;
11 require_mods(qw(json DBD::SQLite Search::Xapian
12 HTTP::Request::Common Plack::Test URI::Escape Plack::Builder));
13 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
14 require PublicInbox::WWW;
15 my ($ro_home, $cfg_path) = setup_public_inboxes;
16 my ($tmpdir, $for_destroy) = tmpdir;
17 my $home = "$tmpdir/home";
18 mkdir $home or BAIL_OUT $!;
19 mkdir "$home/.public-inbox" or BAIL_OUT $!;
20 my $pi_config = "$home/.public-inbox/config";
21 cp("$ro_home/.public-inbox/config", $pi_config) or BAIL_OUT;
22 my $env = { HOME => $home };
23 run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
25 open my $cfgfh, '>', $pi_config or BAIL_OUT;
27 print $cfgfh <<EOM or BAIL_OUT;
30 url = http://bogus.example.com/all
33 my $www = PublicInbox::WWW->new(PublicInbox::Config->new($pi_config));
36 my $res = $cb->(GET('/all/'));
37 is($res->code, 200, '/all/ good');
38 $res = $cb->(GET('/all/new.atom', Host => 'usethis.example.com'));
39 like($res->content, qr!http://usethis\.example\.com/!s,
40 'Host: header respected in Atom feed');
41 unlike($res->content, qr!http://bogus\.example\.com/!s,
42 'default URL ignored with different host header');
44 test_psgi(sub { $www->call(@_) }, $client);
45 %$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);
46 test_httpd($env, $client);