From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: "Thomas Weißschuh" <thomas@t-8ch.de>
Subject: [PATCH 1/2] gzip_filter: delay async wcb call
Date: Mon, 25 Oct 2021 02:45:52 +0000 [thread overview]
Message-ID: <20211025024553.14875-2-e@80x24.org> (raw)
In-Reply-To: <20211025024553.14875-1-e@80x24.org>
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>
---
lib/PublicInbox/GzipFilter.pm | 19 +++++++++++++------
lib/PublicInbox/Mbox.pm | 2 +-
lib/PublicInbox/WwwAtomStream.pm | 4 ++--
lib/PublicInbox/WwwStream.pm | 5 ++---
4 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/lib/PublicInbox/GzipFilter.pm b/lib/PublicInbox/GzipFilter.pm
index c62161710725..c4858a971495 100644
--- a/lib/PublicInbox/GzipFilter.pm
+++ b/lib/PublicInbox/GzipFilter.pm
@@ -54,7 +54,7 @@ sub psgi_response {
$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
@@ -114,9 +114,17 @@ sub translate ($$) {
}
}
+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?
- $_[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
@@ -145,10 +153,9 @@ sub zflush ($;$) {
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;
}
sub bail {
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index dede4825ff13..4f84eea6745d 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -47,7 +47,7 @@ sub async_eml { # for async_blob_cb
$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));
}
sub res_hdr ($$) {
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 5d32294eec15..82895db6373e 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -28,7 +28,7 @@ sub async_next ($) {
if (my $smsg = $ctx->{smsg} = $ctx->{cb}->($ctx)) {
$ctx->smsg_blob($smsg);
} else {
- $ctx->{http_out}->write($ctx->translate('</feed>'));
+ $ctx->write('</feed>');
$ctx->close;
}
};
@@ -38,7 +38,7 @@ sub async_next ($) {
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 response {
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 5be5ed0cad59..6d7c447fe6a2 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -32,7 +32,7 @@ sub init {
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));
}
sub html_top ($) {
@@ -187,8 +187,7 @@ sub async_next ($) {
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
}
};
next prev parent reply other threads:[~2021-10-25 2:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-25 2:45 [PATCH 0/2] www: respect charset in $MSGID/raw display Eric Wong
2021-10-25 2:45 ` Eric Wong [this message]
2021-10-25 2:45 ` [PATCH 2/2] www: $MSGID/raw: set charset in HTTP response Eric Wong
2021-10-25 6:32 ` Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211025024553.14875-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
--cc=thomas@t-8ch.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).