config snippet for mirrors.
+EOF
+ my @nntp = map { qq($_) } @{$ibx->nntp_url};
+ if (@nntp) {
+ $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 .= " note: .onion URLs require Tor: ";
+ $urls .= qq[$TOR_URL];
+ }
+ '
'.join("\n\n",
+ $desc,
$urls,
- 'served with software from public-inbox: '
- ."$url",
+ coderepos($ctx),
+ 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;
-
- if (my $mid = $self->{cb}) { # middle
- $mid = $mid->($nr, $self->{ctx}) and return $mid;
+ my ($ctx) = @_;
+ my $cb = $ctx->{cb} or return;
+ while (defined(my $x = $cb->($ctx))) { # x = smsg or scalar non-ref
+ if (ref($x)) { # smsg
+ my $eml = $ctx->{ibx}->smsg_eml($x) or next;
+ $ctx->{smsg} = $x;
+ return $ctx->translate($cb->($ctx, $eml));
+ } else { # scalar
+ return $ctx->translate($x);
+ }
}
+ delete $ctx->{cb};
+ $ctx->zflush(_html_end($ctx));
+}
- delete $self->{cb} ? _html_end($self) : undef;
+sub html_oneshot ($$;$) {
+ my ($ctx, $code, $sref) = @_;
+ my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8',
+ 'Content-Length' => undef ];
+ bless $ctx, __PACKAGE__;
+ $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
+ $ctx->{base_url} //= do {
+ $ctx->zmore(html_top($ctx));
+ base_url($ctx);
+ };
+ $ctx->zmore($$sref) if $sref;
+ my $bdy = $ctx->zflush(_html_end($ctx));
+ $res_hdr->[3] = bytes::length($bdy);
+ [ $code, $res_hdr, [ $bdy ] ]
}
-sub close {}
+sub async_next ($) {
+ my ($http) = @_; # PublicInbox::HTTP
+ my $ctx = $http->{forward} or return;
+ eval {
+ if (my $smsg = $ctx->{smsg} = $ctx->{cb}->($ctx)) {
+ $ctx->smsg_blob($smsg);
+ } else {
+ $ctx->{http_out}->write(
+ $ctx->translate(_html_end($ctx)));
+ $ctx->close; # GzipFilter->close
+ }
+ };
+ warn "E: $@" if $@;
+}
+
+sub aresponse {
+ my ($ctx, $code, $cb) = @_;
+ my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
+ init($ctx, $cb);
+ $ctx->psgi_response($code, $res_hdr);
+}
1;