]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wwwstream: eliminate ::response, use html_oneshot
authorEric Wong <e@yhbt.net>
Sun, 5 Jul 2020 23:27:52 +0000 (23:27 +0000)
committerEric Wong <e@yhbt.net>
Mon, 6 Jul 2020 20:01:15 +0000 (20:01 +0000)
All of our streaming responses use ::aresponse, now, and our
synchronous responses use html_oneshot.  So there's no need
for the old WwwStream::response.

lib/PublicInbox/View.pm
lib/PublicInbox/WwwStream.pm

index 138e0c3a217d6173de7049c577fcc0ea72769594..895e4f278dfff8b76e1a1e5c5949cf42352c7364 100644 (file)
@@ -14,7 +14,7 @@ use PublicInbox::MID qw(id_compress mids mids_for_index references
                        $MID_EXTRACT);
 use PublicInbox::MsgIter;
 use PublicInbox::Address;
                        $MID_EXTRACT);
 use PublicInbox::MsgIter;
 use PublicInbox::Address;
-use PublicInbox::WwwStream;
+use PublicInbox::WwwStream qw(html_oneshot);
 use PublicInbox::Reply;
 use PublicInbox::ViewDiff qw(flush_diff);
 use PublicInbox::Eml;
 use PublicInbox::Reply;
 use PublicInbox::ViewDiff qw(flush_diff);
 use PublicInbox::Eml;
@@ -45,25 +45,20 @@ sub msg_page_i {
        }
 }
 
        }
 }
 
-# /$INBOX/$MESSAGE_ID/ for unindexed v1 inboxes
-sub no_over_i {
+# /$INBOX/$MSGID/ for unindexed v1 inboxes
+sub no_over_html ($) {
        my ($ctx) = @_;
        my ($ctx) = @_;
-       my $eml = delete $ctx->{eml} or return;
+       my $bref = $ctx->{-inbox}->msg_by_mid($ctx->{mid}) or return; # 404
+       my $eml = PublicInbox::Eml->new($bref);
        my $hdr = $eml->header_obj;
        $ctx->{mhref} = '';
        my $hdr = $eml->header_obj;
        $ctx->{mhref} = '';
+       PublicInbox::WwwStream::init($ctx);
        my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($hdr, $ctx);
        multipart_text_as_html($eml, $ctx);
        delete $ctx->{obuf};
        $$obuf .= '</pre><hr>';
        eval { $$obuf .= html_footer($ctx, $hdr) };
        my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($hdr, $ctx);
        multipart_text_as_html($eml, $ctx);
        delete $ctx->{obuf};
        $$obuf .= '</pre><hr>';
        eval { $$obuf .= html_footer($ctx, $hdr) };
-       $$obuf
-}
-
-sub no_over_html ($) {
-       my ($ctx) = @_;
-       my $bref = $ctx->{-inbox}->msg_by_mid($ctx->{mid}) or return; # 404
-       $ctx->{eml} = PublicInbox::Eml->new($bref);
-       PublicInbox::WwwStream::response($ctx, 200, \&no_over_i);
+       html_oneshot($ctx, 200, $obuf);
 }
 
 # public functions: (unstable)
 }
 
 # public functions: (unstable)
@@ -1169,12 +1164,6 @@ sub pagination_footer ($$) {
        "<hr><pre>page: $next$prev</pre>";
 }
 
        "<hr><pre>page: $next$prev</pre>";
 }
 
-sub index_nav { # callback for WwwStream::getline
-       my ($ctx) = @_;
-       return $ctx->html_top if exists $ctx->{-html_tip};
-       pagination_footer($ctx, '.')
-}
-
 sub paginate_recent ($$) {
        my ($ctx, $lim) = @_;
        my $t = $ctx->{qp}->{t} || '';
 sub paginate_recent ($$) {
        my ($ctx, $lim) = @_;
        my $t = $ctx->{qp}->{t} || '';
@@ -1223,7 +1212,8 @@ sub index_topics {
        if (@$msgs) {
                walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic);
        }
        if (@$msgs) {
                walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic);
        }
-       PublicInbox::WwwStream::response($ctx, dump_topics($ctx), \&index_nav);
+       html_oneshot($ctx, dump_topics($ctx), \pagination_footer($ctx, '.'));
+
 }
 
 sub thread_adj_level {
 }
 
 sub thread_adj_level {
index eecc27019da163d095d0c933b79b1fedf298d0af..7d257a191b0dda96558f969cc1b45d693f726942 100644 (file)
@@ -29,14 +29,6 @@ sub init {
        bless $ctx, __PACKAGE__;
 }
 
        bless $ctx, __PACKAGE__;
 }
 
-sub response {
-       my ($ctx, $code, $cb) = @_;
-       my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
-       init($ctx, $cb);
-       $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
-       [ $code, $res_hdr, $ctx ]
-}
-
 sub async_eml { # ->{async_eml} for async_blob_cb
        my ($ctx, $eml) = @_;
        $ctx->{http_out}->write($ctx->translate($ctx->{cb}->($ctx, $eml)));
 sub async_eml { # ->{async_eml} for async_blob_cb
        my ($ctx, $eml) = @_;
        $ctx->{http_out}->write($ctx->translate($ctx->{cb}->($ctx, $eml)));
@@ -174,17 +166,18 @@ sub getline {
 
 sub html_oneshot ($$;$) {
        my ($ctx, $code, $sref) = @_;
 
 sub html_oneshot ($$;$) {
        my ($ctx, $code, $sref) = @_;
-       $ctx->{base_url} = base_url($ctx);
-       bless $ctx, __PACKAGE__;
-       my @bdy;
        my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8',
                'Content-Length' => undef ];
        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->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
-       $ctx->zmore(html_top($ctx));
+       $ctx->{base_url} //= do {
+               $ctx->zmore(html_top($ctx));
+               base_url($ctx);
+       };
        $ctx->zmore($$sref) if $sref;
        $ctx->zmore($$sref) if $sref;
-       $bdy[0] = $ctx->zflush(_html_end($ctx));
-       $res_hdr->[3] = bytes::length($bdy[0]);
-       [ $code, $res_hdr, \@bdy ]
+       my $bdy = $ctx->zflush(_html_end($ctx));
+       $res_hdr->[3] = bytes::length($bdy);
+       [ $code, $res_hdr, [ $bdy ] ]
 }
 
 sub async_next ($) {
 }
 
 sub async_next ($) {