{name} $dir/ $http \\
+ $addrs
+ public-inbox-index $dir
+EOF
+ } else { # v1
+ $urls .= "\n";
+ }
+
+ my $cfg_link = ($ctx->{-upfx} // '').'_/text/config/raw';
+ $urls .= qq(\nExample config snippet for mirrors\n);
+ my @nntp = map { qq($_) } @{$ibx->nntp_url};
+ if (@nntp) {
+ $urls .= "\n";
+ $urls .= @nntp == 1 ? 'Newsgroup' : 'Newsgroups are';
+ $urls .= ' available over NNTP:';
+ $urls .= "\n\t" . join("\n\t", @nntp) . "\n";
}
- my $url = PublicInbox::Hval::prurl($ctx->{env}, PI_URL);
- ''.join("\n",
- '- ' . $desc,
+ if ($urls =~ m!\b[^:]+://\w+\.onion/!) {
+ $urls .= "\n note: .onion URLs require Tor: ";
+ $urls .= qq[$TOR_URL];
+ }
+ '
'.join("\n\n",
+ $desc,
$urls,
- 'served with software from public-inbox: '
- ."$url",
+ code_footer($ctx->{env})
).'
';
}
+# callback for HTTP.pm (and any other PSGI servers)
sub getline {
- my ($self) = @_;
- my $nr = $self->{nr}++;
-
- return _html_top($self) if $nr == 0;
+ my ($ctx) = @_;
+ my $cb = $ctx->{cb};
+ my $buf = $cb->($ctx) if $cb;
+ $buf //= delete($ctx->{cb}) ? _html_end($ctx) : undef;
- if (my $mid = $self->{cb}) { # middle
- $mid = $mid->($nr, $self->{ctx}) and return $mid;
- }
+ # gzf may be GzipFilter, `undef' or `0'
+ my $gzf = $ctx->{gzf} or return $buf;
- delete $self->{cb} ? _html_end($self) : undef;
+ return $gzf->translate($buf) if defined $buf;
+ $ctx->{gzf} = 0; # next call to ->getline returns $buf (== undef)
+ $gzf->translate(undef);
}
-sub close {}
+sub html_oneshot ($$;$) {
+ my ($ctx, $code, $sref) = @_;
+ $ctx->{base_url} = base_url($ctx);
+ bless $ctx, __PACKAGE__;
+ my @x;
+ my $h = [ 'Content-Type' => 'text/html; charset=UTF-8',
+ 'Content-Length' => undef ];
+ if (my $gzf = gzf_maybe($h, $ctx->{env})) {
+ $gzf->zmore(html_top($ctx));
+ $gzf->zmore($$sref) if $sref;
+ $x[0] = $gzf->zflush(_html_end($ctx));
+ $h->[3] = length($x[0]);
+ } else {
+ @x = (html_top($ctx), $sref ? $$sref : (), _html_end($ctx));
+ $h->[3] += bytes::length($_) for @x;
+ }
+ [ $code, $h, \@x ]
+}
1;