aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@fury.ukcod.org.uk>2011-03-03 19:08:19 +0000
committerMatthew Somerville <matthew@fury.ukcod.org.uk>2011-03-03 19:08:19 +0000
commitf697c88f46b7cf100e64e37c532e2a842b15dc6e (patch)
treedce1842c5bd61f64c93cad381b1d60e09cf97ef4 /perllib
parent8033a55579ccecb92c781528fdeebd666f077978 (diff)
binmode is ignored by FastCGI. This didn't matter on lenny, where FCGI.pm 0.67 happily prints out Unicode strings as UTF-8 (the internal encoding). This was reported as a bug (rt.cpan.org #52400), and FCGI.pm version 0.69 (and thus 0.71 as present on squeeze) changed to call downgrade() on incoming Unicode strings, meaning the output becomes either Latin-1 (or EBCDIC), or a croak due to a Unicode character not fitting into that. The old behaviour of FCGI seemed perfectly acceptable to me when it was given characters, not bytes, and I'm not sure why the change was made - certainly downgrade() seems a bad choice given it could be any Unicode string passed in, I'd have gone with encode() (which would be the old behaviour still). Anyway, we redirect STDOUT to a string, capture it, and then print out the Unicode string (everything internal should be Unicode strings) manually encoded to UTF-8. This should work in CGI, or pre/post 0.69 FastCGI.
Diffstat (limited to 'perllib')
-rw-r--r--perllib/Page.pm7
1 files changed, 5 insertions, 2 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 96bfff10f..f5d97d63c 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -21,6 +21,7 @@ use File::Slurp;
use HTTP::Date; # time2str
use Image::Magick;
use Image::Size;
+use IO::String;
use POSIX qw(strftime);
use URI::Escape;
use Text::Template;
@@ -52,15 +53,17 @@ my $lastmodified;
sub do_fastcgi {
my ($func, $lm, $binary) = @_;
- binmode(STDOUT, ":utf8") unless $binary;
-
try {
my $W = new mySociety::WatchUpdate();
while (my $q = new mySociety::Web(unicode => 1)) {
next if $lm && $q->Maybe304($lm);
$lastmodified = $lm;
microsite($q);
+ my $str_fh = IO::String->new;
+ my $old_fh = select($str_fh);
&$func($q);
+ select($old_fh) if defined $old_fh;
+ print encode_utf8(${$str_fh->string_ref});
dbh()->rollback() if $mySociety::DBHandle::conf_ok;
$W->exit_if_changed();
}