+ my $http_out = http_out($self) // return;
+ $http_out->write($self->zflush);
+ (delete($self->{http_out}) // return)->close;
+}
+
+sub bail {
+ my $self = shift;
+ if (my $env = $self->{env}) {
+ warn @_, "\n";
+ my $http = $env->{'psgix.io'} or return; # client abort
+ eval { $http->close }; # should hit our close
+ warn "E: error in http->close: $@" if $@;
+ eval { $self->close }; # just in case...
+ warn "E: error in self->close: $@" if $@;
+ } else {
+ warn @_, "\n";
+ }
+}
+
+# this is public-inbox-httpd-specific
+sub async_blob_cb { # git->cat_async callback
+ my ($bref, $oid, $type, $size, $self) = @_;
+ my $http = $self->{env}->{'psgix.io'}; # PublicInbox::HTTP
+ $http->{forward} or return; # client aborted
+ my $smsg = $self->{smsg} or bail($self, 'BUG: no smsg');
+ if (!defined($oid)) {
+ # it's possible to have TOCTOU if an admin runs
+ # public-inbox-(edit|purge), just move onto the next message
+ warn "E: $smsg->{blob} missing in $self->{ibx}->{inboxdir}\n";
+ return $http->next_step($self->can('async_next'));
+ }
+ $smsg->{blob} eq $oid or bail($self, "BUG: $smsg->{blob} != $oid");
+ eval { $self->async_eml(PublicInbox::Eml->new($bref)) };
+ bail($self, "E: async_eml: $@") if $@;
+ if ($self->{-low_prio}) { # run via PublicInbox::WWW::event_step
+ push(@{$self->{www}->{-low_prio_q}}, $self) == 1 and
+ PublicInbox::DS::requeue($self->{www});
+ } else {
+ $http->next_step($self->can('async_next'));
+ }
+}
+
+sub smsg_blob {
+ my ($self, $smsg) = @_;
+ ibx_async_cat($self->{ibx}, $smsg->{blob}, \&async_blob_cb, $self);