#
# In newer versions, public-inbox-httpd supports a backpressure-aware
# pull/push model which also accounts for slow git blob storage.
-# {async_next} callbacks only run when the DS {wbuf} is drained
-# {async_eml} callbacks only run when a blob arrives from git.
+# async_next callbacks only run when the DS {wbuf} is drained
+# async_eml callbacks only run when a blob arrives from git.
#
# We continue to support getline+close for generic PSGI servers.
package PublicInbox::GzipFilter;
sub gzf_maybe ($$) { bless { gz => gz_or_noop(@_) }, __PACKAGE__ }
sub psgi_response {
- my ($self, $code, $res_hdr, $next_cb, $eml_cb) = @_;
+ my ($self, $code, $res_hdr) = @_;
my $env = $self->{env};
$self->{gz} //= gz_or_noop($res_hdr, $env);
if ($env->{'pi-httpd.async'}) {
- $self->{async_next} = $next_cb;
- $self->{async_eml} = $eml_cb;
my $http = $env->{'psgix.io'}; # PublicInbox::HTTP
$http->{forward} = $self;
sub {
my ($wcb) = @_; # -httpd provided write callback
$self->{http_out} = $wcb->([$code, $res_hdr]);
- $next_cb->($http); # start stepping
+ $self->can('async_next')->($http); # start stepping
};
} else { # generic PSGI code path
[ $code, $res_hdr, $self ];
# 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->{-inbox}->{inboxdir}\n";
- return $http->next_step($self->{async_next});
+ return $http->next_step($self->can('async_next'));
}
$smsg->{blob} eq $oid or bail($self, "BUG: $smsg->{blob} != $oid");
- eval { $self->{async_eml}->($self, PublicInbox::Eml->new($bref)) };
+ eval { $self->async_eml(PublicInbox::Eml->new($bref)) };
bail($self, "E: async_eml: $@") if $@;
- $http->next_step($self->{async_next});
+ $http->next_step($self->can('async_next'));
}
sub smsg_blob {
}
}
-# called by PublicInbox::DS::write
+# called by PublicInbox::DS::write after http->next_step
sub async_next {
my ($http) = @_; # PublicInbox::HTTP
my $ctx = $http->{forward} or return; # client aborted
warn "E: $@" if $@;
}
-sub async_eml { # ->{async_eml} for async_blob_cb
+sub async_eml { # for async_blob_cb
my ($ctx, $eml) = @_;
my $smsg = delete $ctx->{smsg};
# next message
my $smsg = $ctx->{smsg} = $over->next_by_mid(@$mip) or return;
my $res_hdr = res_hdr($ctx, $smsg->{subject});
bless $ctx, __PACKAGE__;
- $ctx->psgi_response(200, $res_hdr, \&async_next, \&async_eml);
+ $ctx->psgi_response(200, $res_hdr);
}
sub msg_hdr ($$;$) {
bless $self, __PACKAGE__;
my $res_hdr = [ 'Content-Type' => 'application/gzip',
'Content-Disposition' => "inline; filename=$fn.mbox.gz" ];
- $self->psgi_response(200, $res_hdr, \&async_next,
- \&PublicInbox::Mbox::async_eml);
+ $self->psgi_response(200, $res_hdr);
}
# called by Plack::Util::foreach or similar (generic PSGI)
$self->zflush;
}
+no warnings 'once';
+*async_eml = \&PublicInbox::Mbox::async_eml;
1;
warn "E: $@" if $@;
}
-sub async_eml { # ->{async_eml} for async_blob_cb
+sub async_eml { # for async_blob_cb
my ($ctx, $eml) = @_;
my $smsg = delete $ctx->{smsg};
$ctx->{http_out}->write($ctx->translate(feed_entry($ctx, $smsg, $eml)))
my ($class, $ctx, $code, $cb) = @_;
my $res_hdr = [ 'Content-Type' => 'application/atom+xml' ];
$class->new($ctx, $cb);
- $ctx->psgi_response($code, $res_hdr, \&async_next, \&async_eml);
+ $ctx->psgi_response($code, $res_hdr);
}
# called once for each message by PSGI server
$res->[2]->[0] = $part;
}
-sub async_eml { # ->{async_eml} for async_blob_cb
+sub async_eml { # for async_blob_cb
my ($ctx, $eml) = @_;
eval { $eml->each_part(\&get_attach_i, $ctx, 1) };
if ($@) {
sub scan_attach ($) { # public-inbox-httpd only
my ($ctx) = @_;
$ctx->{env}->{'psgix.io'}->{forward} = $ctx;
- $ctx->{async_eml} = \&async_eml;
- $ctx->{async_next} = \&async_next;
$ctx->smsg_blob($ctx->{smsg});
}
bless $ctx, __PACKAGE__;
}
-sub async_eml { # ->{async_eml} for async_blob_cb
+sub async_eml { # for async_blob_cb
my ($ctx, $eml) = @_;
$ctx->{http_out}->write($ctx->translate($ctx->{cb}->($ctx, $eml)));
}
my ($ctx, $code, $cb) = @_;
my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
init($ctx, $cb);
- $ctx->psgi_response($code, $res_hdr, \&async_next, \&async_eml);
+ $ctx->psgi_response($code, $res_hdr);
}
1;