This will let us modify the response header later to set
a proper charset for Content-Type when displaying raw
messages.
Cc: Thomas Weißschuh <thomas@t-8ch.de>
$http->{forward} = $self;
sub {
my ($wcb) = @_; # -httpd provided write callback
$http->{forward} = $self;
sub {
my ($wcb) = @_; # -httpd provided write callback
- $self->{http_out} = $wcb->([$code, $res_hdr]);
+ $self->{wcb_args} = [ $code, $res_hdr, $wcb ];
$self->can('async_next')->($http); # start stepping
};
} else { # generic PSGI code path
$self->can('async_next')->($http); # start stepping
};
} else { # generic PSGI code path
+sub http_out ($) {
+ my ($self) = @_;
+ $self->{http_out} //= do {
+ my $args = delete $self->{wcb_args} // return undef;
+ pop(@$args)->($args); # $wcb->([$code, $hdr_ary])
+ };
+}
+
sub write {
# my $ret = bytes::length($_[1]); # XXX does anybody care?
sub write {
# my $ret = bytes::length($_[1]); # XXX does anybody care?
- $_[0]->{http_out}->write(translate($_[0], $_[1]));
+ http_out($_[0])->write(translate($_[0], $_[1]));
}
# similar to ->translate; use this when we're sure we know we have
}
# similar to ->translate; use this when we're sure we know we have
sub close {
my ($self) = @_;
sub close {
my ($self) = @_;
- if (my $http_out = delete $self->{http_out}) {
- $http_out->write(zflush($self));
- $http_out->close;
- }
+ my $http_out = http_out($self) // return;
+ $http_out->write(zflush($self));
+ delete($self->{http_out})->close;
$ctx->{smsg} = $ctx->{ibx}->over->next_by_mid(@{$ctx->{next_arg}});
$ctx->zmore(msg_hdr($ctx, $eml));
$ctx->{smsg} = $ctx->{ibx}->over->next_by_mid(@{$ctx->{next_arg}});
$ctx->zmore(msg_hdr($ctx, $eml));
- $ctx->{http_out}->write($ctx->translate(msg_body($eml)));
+ $ctx->write(msg_body($eml));
if (my $smsg = $ctx->{smsg} = $ctx->{cb}->($ctx)) {
$ctx->smsg_blob($smsg);
} else {
if (my $smsg = $ctx->{smsg} = $ctx->{cb}->($ctx)) {
$ctx->smsg_blob($smsg);
} else {
- $ctx->{http_out}->write($ctx->translate('</feed>'));
+ $ctx->write('</feed>');
sub async_eml { # for async_blob_cb
my ($ctx, $eml) = @_;
my $smsg = delete $ctx->{smsg};
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)))
+ $ctx->write(feed_entry($ctx, $smsg, $eml));
sub async_eml { # for async_blob_cb
my ($ctx, $eml) = @_;
sub async_eml { # for async_blob_cb
my ($ctx, $eml) = @_;
- $ctx->{http_out}->write($ctx->translate($ctx->{cb}->($ctx, $eml)));
+ $ctx->write($ctx->{cb}->($ctx, $eml));
if (my $smsg = $ctx->{smsg} = $ctx->{cb}->($ctx)) {
$ctx->smsg_blob($smsg);
} else {
if (my $smsg = $ctx->{smsg} = $ctx->{cb}->($ctx)) {
$ctx->smsg_blob($smsg);
} else {
- $ctx->{http_out}->write(
- $ctx->translate(_html_end($ctx)));
+ $ctx->write(_html_end($ctx));
$ctx->close; # GzipFilter->close
}
};
$ctx->close; # GzipFilter->close
}
};