From: Eric Wong Date: Sun, 5 Jul 2020 23:27:52 +0000 (+0000) Subject: wwwstream: eliminate ::response, use html_oneshot X-Git-Tag: v1.6.0~264 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=1cf5a6129b5ae4991275862aab539ddea812890a wwwstream: eliminate ::response, use html_oneshot 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. --- diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 138e0c3a..895e4f27 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 eecc2701..7d257a19 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 ($) {