+# this is public-inbox-httpd-specific
+sub mboxgz_blob_cb { # git->cat_async callback
+ my ($bref, $oid, $type, $size, $self) = @_;
+ my $http = $self->{ctx}->{env}->{'psgix.io'} or return; # client abort
+ my $smsg = delete $self->{smsg} or die '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
+ return $http->next_step(\&async_next);
+ } else {
+ $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid";
+ }
+ $self->zmore(msg_hdr($self->{ctx},
+ PublicInbox::Eml->new($bref)->header_obj,
+ $smsg->{mid}));
+
+ # PublicInbox::HTTP::{Chunked,Identity}::write
+ $self->{http_out}->write($self->translate(msg_body($$bref)));
+
+ $http->next_step(\&async_next);
+}
+
+# this is public-inbox-httpd-specific
+sub async_step ($) {
+ my ($self) = @_;
+ if (my $smsg = $self->{smsg} = $self->{cb}->($self->{ctx})) {
+ git_async_cat($self->{ctx}->{-inbox}->git, $smsg->{blob},
+ \&mboxgz_blob_cb, $self);
+ } elsif (my $out = delete $self->{http_out}) {
+ $out->write($self->zflush);
+ $out->close;
+ }
+}
+
+# called by PublicInbox::DS::write
+sub async_next {
+ my ($http) = @_; # PublicInbox::HTTP
+ async_step($http->{forward});
+}
+
+# called by PublicInbox::HTTP::close, or any other PSGI server
+sub close { !!delete($_[0]->{http_out}) }
+