I noticed a while ago a Perl script file included on my blog wasn’t
served properly, since the charset wasn’t announced and web browsers
didn’t display it properly. The received file was still valid UTF-8
(hello, little ©
character), at least!
First, wrong intuition
Reading Apache’s /etc/apache2/conf.d/charset
it looks like the
following directive might help:
AddDefaultCharset UTF-8
but comments there suggest reading the documentation! And indeed that alone
isn’t sufficient since this would only affect text/plain
and
text/html
. The above directive would have to be combined with
something like this in /etc/apache2/mods-enabled/mime.conf
:
AddType text/plain .pl
Real solution
To avoid any side effects on other file types, the easiest way forward
seems to avoid setting AddDefaultCharset
and to associate the
UTF-8
charset with .pl
files instead, keeping the text/x-perl
MIME type, with this single directive (again in
/etc/apache2/mods-enabled/mime.conf
):
AddCharset UTF-8 .pl
Looking at response headers (wget -d
) we’re moving from:
Content-Type: text/x-perl
to:
Content-Type: text/x-perl; charset=utf-8
Conclusion
Nothing really interesting, or new. Just a small reminder that tweaking
options too hastily is sometimes a bad idea. In other news, another Perl
script is coming up soon. :)