my $have_tslash = ($key =~ s!/\z!!) if !$raw;
my $txt = '';
- my $hdr = [ 'Content-Type', 'text/plain', 'Content-Length', undef ];
- if (!_default_text($ctx, $key, $hdr, \$txt)) {
+ if (!_default_text($ctx, $key, \$txt)) {
$code = 404;
$txt = "404 Not Found ($key)\n";
}
my $env = $ctx->{env};
if ($raw) {
- $txt = gzf_maybe($hdr, $env)->zflush($txt) if $code == 200;
- $hdr->[3] = length($txt);
- return [ $code, $hdr, [ $txt ] ]
+ 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);
+ return [ $code, $h, [ $txt ] ]
}
# enforce trailing slash for "wget -r" compatibility
$txt = ascii_html($txt);
}
$txt = '<pre>' . $l->linkify_2($txt) . '</pre>';
+ $txt =~ s!^search$!<a\nid=search>search</a>!sm;
$txt =~ s!\bPOP3\b!<a\nid=pop3>POP3</a>!;
- $txt =~ s!\bNewsgroups\b!<a\nid=nntp>Newsgroups</a>!;
+ $txt =~ s!\b(Newsgroups?)\b!<a\nid=nntp>$1</a>!;
$txt =~ s!\bIMAP\b!<a\nid=imap>IMAP</a>!;
- PublicInbox::WwwStream::html_oneshot($ctx, $code, \$txt);
+ PublicInbox::WwwStream::html_oneshot($ctx, $code, $txt);
}
sub _srch_prefix ($$) {
}
# n.b. this is a perfect candidate for memoization
-sub inbox_config ($$$) {
- my ($ctx, $hdr, $txt) = @_;
+sub inbox_config ($$) {
+ my ($ctx, $txt) = @_;
my $ibx = $ctx->{ibx};
- push @$hdr, 'Content-Disposition', 'inline; filename=inbox.config';
+ push @{$ctx->{-res_hdr}},
+ 'Content-Disposition', 'inline; filename=inbox.config';
my $t = eval { $ibx->mm->created_at };
- push(@$hdr, 'Last-Modified', time2str($t)) if $t;
+ push(@{$ctx->{-res_hdr}}, 'Last-Modified', time2str($t)) if $t;
my $name = dq_escape($ibx->{name});
my $inboxdir = '/path/to/top-level-inbox';
my $base_url = $ibx->base_url($ctx->{env});
}
# n.b. this is a perfect candidate for memoization
-sub extindex_config ($$$) {
- my ($ctx, $hdr, $txt) = @_;
+sub extindex_config ($$) {
+ my ($ctx, $txt) = @_;
my $ibx = $ctx->{ibx};
- push @$hdr, 'Content-Disposition', 'inline; filename=extindex.config';
+ push @{$ctx->{-res_hdr}},
+ 'Content-Disposition', 'inline; filename=extindex.config';
my $name = dq_escape($ibx->{name});
my $base_url = $ibx->base_url($ctx->{env});
$$txt .= <<EOS;
my ($ctx, $top_url) = @_;
my $cr = $ctx->{ibx}->{coderepo} // return ();
my $cfg = $ctx->{www}->{pi_cfg};
- my @ret;
- for my $cr_name (@$cr) {
- $ret[0] //= do {
- my $thing = $ctx->{ibx}->can('cloneurl') ?
- 'public inbox' : 'external index';
- <<EOF;
-Code repositories for project(s) associated with this $thing
-EOF
- };
- my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl");
- if ($urls) {
- for (@$urls) {
- # relative or absolute URL?, prefix relative
- # "foo.git" with appropriate number of "../"
- my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ :
- $top_url.$_;
- $ret[0] .= "\n\t" . prurl($ctx->{env}, $u);
- }
- } else {
- $ret[0] .= qq[\n\t$cr_name.git (no URL configured)];
+ my $buf = 'Code repositories for project(s) associated with this '.
+ $ctx->{ibx}->thing_type . "\n";
+ for my $git (@{$ctx->{www}->{pi_cfg}->repo_objs($ctx->{ibx})}) {
+ for ($git->pub_urls($ctx->{env})) {
+ my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ : $top_url.$_;
+ $buf .= "\n\t" . prurl($ctx->{env}, $u);
}
}
- @ret; # may be empty, this sub is called as an arg for join()
+ ($buf);
}
sub _add_non_http_urls ($$) {
$ctx->{ibx}->can('nntp_url') or return; # TODO extindex can have IMAP
my $urls = $ctx->{ibx}->imap_url($ctx);
if (@$urls) {
- $$txt .= "\nIMAP subfolder(s) are available under:";
- $$txt .= "\n " . join("\n ", @$urls);
+ $urls = join("\n ", @$urls);
+ $urls =~ s!://([^/@]+)/!://;AUTH=ANONYMOUS\@$1/!sg;
$$txt .= <<EOM
+IMAP subfolder(s) are available under:
+ $urls
# each subfolder (starting with `0') holds 50K messages at most
EOM
}
1;
}
-sub _default_text ($$$$) {
- my ($ctx, $key, $hdr, $txt) = @_;
+sub _default_text ($$$) {
+ my ($ctx, $key, $txt) = @_;
if ($key eq 'mirror') {
return _mirror_help($ctx, $txt);
} elsif ($key eq 'color') {
return _colors_help($ctx, $txt);
} elsif ($key eq 'config') {
return $ctx->{ibx}->can('cloneurl') ?
- inbox_config($ctx, $hdr, $txt) :
- extindex_config($ctx, $hdr, $txt);
+ inbox_config($ctx, $txt) :
+ extindex_config($ctx, $txt);
}
return if $key ne 'help'; # TODO more keys?