Hopefully this forces us to generate valid UTF-8 data.
-binmode STDOUT, ':utf8';
-
my $ret = main();
my ($status, $headers, $body) = @$ret;
my $ret = main();
my ($status, $headers, $body) = @$ret;
if (@ARGV && $ARGV[0] eq 'static') {
print $body;
} else { # CGI
if (@ARGV && $ARGV[0] eq 'static') {
print $body;
} else { # CGI
my $x = mid2blob($ctx);
$x ? [ "200 OK", {'Content-Type' => 'text/plain'}, $$x ] : r404();
}
my $x = mid2blob($ctx);
$x ? [ "200 OK", {'Content-Type' => 'text/plain'}, $$x ] : r404();
}
+
+sub set_binmode {
+ my ($headers) = @_;
+ if ($headers->{'Content-Type'} eq 'text/plain') {
+ # no way to validate raw messages, mixed encoding is possible.
+ binmode STDOUT;
+ } else { # strict encoding for HTML and XML
+ binmode STDOUT, ':encoding(UTF-8)';
+ }
+}