our $MAX_SIZE = 1024 * 1024; # TODO: configurable
my $BIN_DETECT = 8000; # same as git
-sub html_i { # WwwStream::getline callback
- my ($nr, $ctx) = @_;
- $nr == 1 ? ${delete $ctx->{obuf}} : undef;
-}
-
sub html_page ($$$) {
my ($ctx, $code, $strref) = @_;
my $wcb = delete $ctx->{-wcb};
$ctx->{-upfx} = '../../'; # from "/$INBOX/$OID/s/"
- $ctx->{obuf} = $strref;
- my $res = PublicInbox::WwwStream->response($ctx, $code, \&html_i);
+ my $res = PublicInbox::WwwStream::oneshot($ctx, $code, $strref);
$wcb ? $wcb->($res) : $res;
}
# noop for HTTP.pm (and any other PSGI servers)
sub close {}
+sub base_url ($) {
+ my $ctx = shift;
+ my $base_url = $ctx->{-inbox}->base_url($ctx->{env});
+ chop $base_url; # no trailing slash for clone
+ $base_url;
+}
+
sub new {
my ($class, $ctx, $cb) = @_;
- my $base_url = $ctx->{-inbox}->base_url($ctx->{env});
- chop $base_url; # no trailing slash for clone
bless {
nr => 0,
cb => $cb || \&close,
ctx => $ctx,
- base_url => $base_url,
+ base_url => base_url($ctx),
}, $class;
}
delete $self->{cb} ? _html_end($self) : undef;
}
+sub oneshot {
+ my ($ctx, $code, $strref) = @_;
+ my $self = bless {
+ ctx => $ctx,
+ base_url => base_url($ctx),
+ }, __PACKAGE__;
+ [ $code, [ 'Content-Type', 'text/html; charset=UTF-8' ],
+ [ _html_top($self), $$strref, _html_end($self) ] ]
+}
+
1;