From 84df9b913203c89b36e0d922acb1a5785a51dca6 Mon Sep 17 00:00:00 2001 From: Thiago Berlitz Rondon Date: Wed, 8 Feb 2012 15:37:08 -0200 Subject: [PATCH 1/2] Make Serialize::JSON likes JSON::XS, without utf8 in _build_encoder to prevent double encoding. Signed-off-by: Thiago Berlitz Rondon --- lib/Catalyst/Action/Serialize/JSON.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Catalyst/Action/Serialize/JSON.pm b/lib/Catalyst/Action/Serialize/JSON.pm index 9f4cf44..42ea100 100644 --- a/lib/Catalyst/Action/Serialize/JSON.pm +++ b/lib/Catalyst/Action/Serialize/JSON.pm @@ -16,7 +16,7 @@ has encoder => ( sub _build_encoder { my $self = shift; - return JSON->new->utf8->convert_blessed; + return JSON->new->convert_blessed; } sub execute { From 22c0d495119f9464193e58afa75add4a753ad830 Mon Sep 17 00:00:00 2001 From: Thiago Berlitz Rondon Date: Wed, 8 Feb 2012 16:20:21 -0200 Subject: [PATCH 2/2] new option to put charset in content_type header. Signed-off-by: Thiago Berlitz Rondon --- lib/Catalyst/Action/SerializeBase.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Catalyst/Action/SerializeBase.pm b/lib/Catalyst/Action/SerializeBase.pm index 8ba1100..67718de 100644 --- a/lib/Catalyst/Action/SerializeBase.pm +++ b/lib/Catalyst/Action/SerializeBase.pm @@ -126,9 +126,16 @@ sub _load_content_plugins { } elsif ($c->request->accept_only) { $c->response->header( 'Vary' => 'Accept' ); } + $c->response->content_type($content_type); } + if ( $config->{'encoding'} ) { + my $res_content_type = $c->response->content_type; + $res_content_type .= '; charset=' . $config->{'encoding'}; + $c->response->content_type( $res_content_type ); + } + return $sclass, $sarg, $content_type; }