about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/ViewVCS.pm8
-rw-r--r--lib/PublicInbox/WwwStream.pm21
2 files changed, 19 insertions, 10 deletions
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 2f8e1c4f..6714e67c 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -31,17 +31,11 @@ my %QP_MAP = ( A => 'oid_a', B => 'oid_b', a => 'path_a', b => 'path_b' );
 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;
 }
 
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 3a867ec3..2dd8b157 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -16,16 +16,21 @@ our $CODE_URL = 'https://public-inbox.org/public-inbox.git';
 # 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;
 }
 
@@ -164,4 +169,14 @@ sub getline {
         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;