perl-asp mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arnon Weinberg <ar...@back2front.ca>
Subject Output character encoding
Date Tue, 05 Jun 2012 09:02:51 GMT

How can I set the output character encoding of Apache::ASP output?

Regular perl/CGI output defaults to ISO-8859-1 encoding, and may be 
easily modified using the use open prama or binmode() function.  Here is 
my test script:

# Latin-1.cgi: ##############

#use open ( ":utf8", ":std" );
#binmode ( STDOUT, ":encoding(ISO-8859-1)" );

use CGI;
print CGI::header();

use Encode;

print Encode::decode('ISO-8859-1',"\xE2"),
       Encode::decode('UTF-8',Encode::encode('UTF-8',"\xE2")),
       "\x{00E2}",
       chr(0x00E2);

#############################

 >perl Latin-1.cgi
Content-Type: text/html; charset=ISO-8859-1

ââââ
 >perl Latin-1.cgi | tail -1 | hexdump
0000000 e2e2 e2e2
0000004

This script correctly produces ISO-8859-1 encoded output.

However, Apache::ASP appears to default to some strange mix of 
ISO-8859-1 and UTF-8 that I can't make sense of.
Additionally, the use open pragma and binmode() function appear to have 
no effect:

# Latin-1.rasp: #############

<%
#use open ( ":utf8", ":std" );
#binmode ( STDOUT, ":encoding(ISO-8859-1)" );

$::Response->{Charset} = "ISO-8859-1";

use Encode;

print Encode::decode('ISO-8859-1',"\xE2"),
       Encode::decode('UTF-8',Encode::encode('UTF-8',"\xE2")),
       "\x{00E2}",
       chr(0x00E2);
%>

#############################

 >asp-perl Latin-1.rasp
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 6
Cache-Control: private

ââââ
 >asp-perl Latin-1.rasp | tail -1 | hexdump
0000000 a2c3 a2c3 e2e2
0000006

For some reason, the first 2 test characters are UTF-8 encoded, and the 
last 2 are ISO-8859-1 encoded.
How can I get the same results as the CGI script above?


-- 
-------------------------------------------------------------------------------
Arnon Weinberg
www.back2front.ca


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Mime
View raw message