From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D51B31F94E for ; Sun, 5 Jul 2020 23:28:14 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 36/43] wwwstream: eliminate ::response, use html_oneshot Date: Sun, 5 Jul 2020 23:27:52 +0000 Message-Id: <20200705232759.3161-37-e@yhbt.net> In-Reply-To: <20200705232759.3161-1-e@yhbt.net> References: <20200705232759.3161-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 28 +++++++++------------------- lib/PublicInbox/WwwStream.pm | 23 ++++++++--------------- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 138e0c3a2..895e4f278 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -14,7 +14,7 @@ use PublicInbox::MID qw(id_compress mids mids_for_index references $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; @@ -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 $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} = ''; + PublicInbox::WwwStream::init($ctx); my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($hdr, $ctx); multipart_text_as_html($eml, $ctx); delete $ctx->{obuf}; $$obuf .= '
'; 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) @@ -1169,12 +1164,6 @@ sub pagination_footer ($$) { "
page: $next$prev
"; } -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} || ''; @@ -1223,7 +1212,8 @@ sub index_topics { 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 { diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index eecc27019..7d257a191 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -29,14 +29,6 @@ sub init { 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))); @@ -174,17 +166,18 @@ sub getline { 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 ]; + bless $ctx, __PACKAGE__; $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; - $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 ($) {