2 # Copyright (C) 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 my ($tmpdir, $for_destroy) = tmpdir();
8 my $v1dir = "$tmpdir/v1.git";
10 use_ok 'PublicInbox::WWW';
11 my $ibx = create_inbox 'test', tmpdir => $v1dir, sub {
13 $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
14 From: Me <me\@example.com>
15 To: You <you\@example.com>
16 Cc: $ibx->{-primary_address}
17 Message-Id: <blah\@example.com>
19 Date: Thu, 01 Jan 1970 00:00:00 +0000
24 my $cfg = cfg_new $tmpdir, <<EOF;
26 address = $ibx->{-primary_address}
29 my $www = PublicInbox::WWW->new($cfg);
30 my $app = builder(sub {
32 mount('/a' => builder(sub { sub { $www->call(@_) } }));
33 mount('/b' => builder(sub { sub { $www->call(@_) } }));
40 $res = $cb->(GET('/a/test/new.atom'));
41 like($res->content, qr!\bhttp://[^/]+/a/test/!,
42 'URLs which exist in Atom feed are mount-aware');
43 unlike($res->content, qr!\b\Qhttp://[^/]+/test/\E!,
44 'No URLs which are not mount-aware');
46 $res = $cb->(GET('/a/test/_/text/mirror/'));
47 like($res->content, qr!git clone --mirror\s+.*?http://[^/]+/a/test\b!s,
48 'clone URL in /text/mirror is mount-aware');
50 $res = $cb->(GET('/a/test/blah%40example.com/raw'));
51 is($res->code, 200, 'OK with URLMap mount');
53 qr/^Message-Id: <blah\@example\.com>\n/sm,
54 'headers appear in /raw');
57 $res = $cb->(GET('/a/test/m/blah%40example.com.html'));
58 is($res->header('Location'),
59 'http://localhost/a/test/blah@example.com/',
60 'redirect functions properly under mount');
62 $res = $cb->(GET('/test/blah%40example.com/'));
63 is($res->code, 404, 'intentional 404 with URLMap mount');
67 require_mods(qw(DBD::SQLite Xapian IO::Uncompress::Gunzip), 3);
68 require_ok 'PublicInbox::SearchIdx';
69 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
72 my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
73 my $gz = $res->content;
75 IO::Uncompress::Gunzip::gunzip(\$gz => \$raw);
76 like($raw, qr!^Message-Id:\x20<blah\@example\.com>\n!sm,
77 'headers appear in /t.mbox.gz mboxrd');