about summary refs log tree commit homepage
path: root/public-inbox-cgi
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-04-10 19:26:40 +0000
committerEric Wong <e@80x24.org>2014-04-11 22:23:58 +0000
commit610e07776ea454ef5b86714f14718540ab0b4dae (patch)
tree3ac117903568fba309a35f58603f3030b919d7f5 /public-inbox-cgi
parent546ff31b4c11d74f63aa4501659224dbf864c21c (diff)
downloadpublic-inbox-610e07776ea454ef5b86714f14718540ab0b4dae.tar.gz
Hopefully this forces us to generate valid UTF-8 data.
Diffstat (limited to 'public-inbox-cgi')
-rwxr-xr-xpublic-inbox-cgi13
1 files changed, 11 insertions, 2 deletions
diff --git a/public-inbox-cgi b/public-inbox-cgi
index 91314f06..cd79a4a7 100755
--- a/public-inbox-cgi
+++ b/public-inbox-cgi
@@ -26,11 +26,10 @@ BEGIN {
         }
 }
 
-binmode STDOUT, ':utf8';
-
 my $ret = main();
 
 my ($status, $headers, $body) = @$ret;
+set_binmode($headers);
 if (@ARGV && $ARGV[0] eq 'static') {
         print $body;
 } else { # CGI
@@ -143,3 +142,13 @@ sub get_mid_txt {
         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)';
+        }
+}