[Catalyst] Forcing charset=utf-8 on all Content-Types for Catalyst::Controller::REST

Nicholas Wehr catalyst at bionikchickens.com
Mon Jul 26 15:57:58 GMT 2010


notice that by default - C::V::JSON will detect utf8 "perl flagged" scalars
and automatically output the utf8 header. I've ran into issues where I was
pulling in file system data via YAML, which was *not* utf8 by default, and
ultimately caused my issue with utf8 display to an extjs javascript panel.

hope this helps.
-nw

On Mon, Jul 26, 2010 at 8:36 AM, Larry Leszczynski <larryl at emailplus.org>wr=
ote:

> Hi Dave -
>
> > After searching google, and reading through all of the relevant
> > documentation, and a considerable portion of the code, we have been
> > unable to locate the correct place to set or override the Content-Type
> > header to append a "charset=3Dutf-8" string, required by our caching pr=
oxy
> > to properly handle the encoding.  We would like a place to handle all
> > mimetypes, so that our JSON, JSONP, and XML interfaces all get the
> > correct charset set.
>
> If you're sure all your content actually is utf-8, one way is to
> subclass Catalyst::View and do something like:
>
> after process =3D> sub {
>
>    my ($self, $c) =3D @_;
>
>    my $ct =3D $c->response->content_type;
>
>    if ($ct)
>    {
>        $ct =3D~ s/;\s*charset=3D.*//i;
>        $ct .=3D '; charset=3Dutf-8';
>    }
>    else
>    {
>        $ct =3D 'text/html; charset=3Dutf-8';
>    }
>
>    $c->response->content_type($ct);
> };
>
>
> Thanks!
> Larry
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100726/398e6=
932/attachment.htm


More information about the Catalyst mailing list