[Catalyst] charset not needed for Catalyst::Action::REST?

Bill Moseley moseley at hank.org
Fri Feb 24 15:50:34 GMT 2012


When using Catalyst::Action::REST the content-type response never includes
a charset.  JSON seems to be handled correctly in code -- JSON strings are
always UTF-8.  Does that mean there is no need to specify a charset on
responses?

And what if a JSON request comes in with a non-UTF8 charset?  Should that
be ignored?  It's application/json, not text/json so maybe there no
encoding issues?

What about other serializations?  YAML is UTF-8 or UTF-16.  Does that mean
the charset needs to be included in response?  And again, if a request
comes in with UTF-16 does it need to be decoded or does that happen in
YAML::Syck?

Event text/html doesn't include a charset in a the "serialized" response.


Does there need to be an additional decoding and encoding layer when using
Catalyst::Action::REST?   Should I force a charset on all responses?


BTW -- doesn't seem like YAML survies a round trip like JSON does:

As expected:

$ perl -MEncode -wle '$x =3D "\x{263A}"; print length( $x )'
1

$ perl -MEncode -wle '$x =3D Encode::encode_utf8("\x{263A}"); print length(
$x )'
3


And also as expected:


$ perl -MJSON  -MEncode -wle 'print
length(JSON::decode_json(JSON::encode_json( ["\x{263A}"]) )->[0])'
1


But YAML drops the utf8 flag:

$ perl -MYAML::Syck  -MEncode -wle 'print
length(YAML::Syck::Load(YAML::Syck::Dump( ["\x{263A}"]) )->[0])'
3




-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120224/02980=
2da/attachment.htm


More information about the Catalyst mailing list