<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>>>> Looks like to a bug to me</p>
<p>tl;dr I'm not sure its a Catalyst bug or problem. It's may be
MY configuration problem or standard violation<br>
</p>
<p><br>
</p>
<p>Here are my investigation results<br>
</p>
<p><br>
</p>
<p>I created a test to reproduce this situation <br>
</p>
<p># catalyst.pl test</p>
<p># test/script/test_create.pl view HTML TT<br>
</p>
<p># [editor] test/lib/test/Controller/Root.pm<br>
</p>
<p>sub index :Path :Args(0)<br>
{<br>
my ( $self, $c ) = @_;<br>
<br>
my $json_text = '{"id":1, "msg":"В Питере пить"}';<br>
$c->response->content_type('application/json');<br>
$c->response->body($json_text);<br>
}<br>
</p>
<p><br>
</p>
<p>and found following:<br>
</p>
<p><br>
</p>
<p> wget -S -O - <a class="moz-txt-link-freetext" href="http://domain.tld:3000">http://domain.tld:3000</a><br>
--2016-07-20 13:56:18-- <a class="moz-txt-link-freetext" href="http://domain.tld:3000/">http://domain.tld:3000/</a><br>
Resolving cary.lv (cary.lv)... aaa.bbb.ccc.ddd<br>
Connecting to domain.tld (domain.tld)|aaa.bbb.ccc.ddd|:3000...
connected.<br>
HTTP request sent, awaiting response...<br>
HTTP/1.0 200 OK<br>
Date: Wed, 20 Jul 2016 10:56:18 GMT<br>
Server: HTTP::Server::PSGI<br>
Content-Type: application/json<br>
X-Catalyst: 5.90106<br>
Content-Length: 42<br>
Length: 42 [application/json]<br>
Saving to: 'STDOUT'<br>
</p>
<p><br>
</p>
<p>content-Length is properly set. I see same using Firefox Dev
tools<br>
</p>
<p>but in the log (build-in test server log)<br>
</p>
<p>[debug] Response Code: 200; Content-Type: application/json;
Content-Length: unknown<br>
</p>
<p><br>
</p>
<p>Exactly same code, but app works as fastcgi daemon and
Apache/2.4.23 (FreeBSD) serves http requests <br>
</p>
<p># wget -S -O - <a class="moz-txt-link-freetext" href="http://domain.tld/">http://domain.tld/</a><br>
--2016-07-20 15:02:28-- <a class="moz-txt-link-freetext" href="http://domain.tld/">http://domain.tld/</a><br>
Resolving domain.tld (domain.tld)... aaa.bbb.ccc.ddd<br>
Connecting to domain.tld (domain.tld)|aaa.bbb.ccc.ddd|:80...
connected.<br>
HTTP request sent, awaiting response...<br>
HTTP/1.1 200 OK<br>
Date: Wed, 20 Jul 2016 12:02:28 GMT<br>
Server: Apache<br>
Set-Cookie: lang=ru; path=/; expires=Thu, 20-Jul-2017 12:02:28
GMT<br>
Set-Cookie: sid=3b2b88c4106b5e06c0c24a5c3a513ccbcb939299;
domain=domain.tld; path=/; expires=Wed, 20-Jul-2016 12:52:28 GMT;
HttpOnly<br>
X-Catalyst: 5.90106<br>
Content-Length: 31<br>
Keep-Alive: timeout=5, max=100<br>
Connection: Keep-Alive<br>
Content-Type: application/json<br>
Length: 31 [application/json]<br>
</p>
<p><br>
</p>
<p>Content length here is in chars not in bytes<br>
</p>
<p>A solution by Aristotle Pagaltzis <br>
</p>
<p> $c->response->body(Encode::encode_utf8 $json_text);</p>
<p>gives proper content length in this situation<br>
</p>
<p>I'm getting same proper content length if I change content type
to 'text/html'</p>
<p><br>
</p>
<p>Finally, I've discovered Catalyst::View::JSON</p>
<p>and it not only solved this problem for me, but also gave me a
much more comfortable solution to work with json <br>
</p>
<p>$c->stash->{msg} = "В Питере пить";<br>
$c->stash->{id} = 1;<br>
$c->forward('View::JSON');<br>
</p>
<p>Works like a charm<br>
</p>
<p><br>
</p>
<p>Taking this opportunity, thank you for this lovely framework!</p>
<p>I'll be happy to provide any additional information if you still
consider there is something should be fixed<br>
</p>
<p><br>
</p>
<p><br>
</p>
<br>
<br>
<br>
<br>
<div class="moz-cite-prefix">19.07.2016 19:10, John Napiorkowski
пишет:<br>
</div>
<blockquote
cite="mid:662285328.1785252.1468944634942.JavaMail.yahoo@mail.yahoo.com"
type="cite">
<div style="color:#000; background-color:#fff;
font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial,
Lucida Grande, sans-serif;font-size:16px">
<div id="yui_3_16_0_1_1468944360128_4375" dir="ltr">Looks like
to a bug to me, although I'm not personally keen on the auto
length setting in Catalyst it should be corrected. I'm happy
to get a patch, or at the very least give me a broken test
case (checkout <a moz-do-not-send="true"
href="https://github.com/perl-catalyst/catalyst-runtime/blob/master/t/utf_incoming.t"
class="" id="yui_3_16_0_1_1468944360128_4381">https://github.com/perl-catalyst/catalyst-runtime/blob/master/t/utf_incoming.t</a> </div>
<div id="yui_3_16_0_1_1468944360128_4452"><br>
</div>
<div id="yui_3_16_0_1_1468944360128_4452" dir="ltr">and see if
you can help me figure it out -jnap</div>
<div id="yui_3_16_0_1_1468944360128_4452" dir="ltr"><br>
</div>
<div id="yui_3_16_0_1_1468944360128_4452" dir="ltr">(created an
issues for this, _<a moz-do-not-send="true"
href="https://github.com/perl-catalyst/catalyst-runtime/issues/143"
class="" id="yui_3_16_0_1_1468944360128_5338">https://github.com/perl-catalyst/catalyst-runtime/issues/143</a></div>
<div id="yui_3_16_0_1_1468944360128_5347"><br>
</div>
<div><br>
</div>
<div id="yui_3_16_0_1_1468944360128_4390"><br>
</div>
<div class="qtdSeparateBR"><br>
<br>
</div>
<div class="yahoo_quoted" style="display: block;">
<div style="font-family: HelveticaNeue, Helvetica Neue,
Helvetica, Arial, Lucida Grande, sans-serif; font-size:
16px;">
<div style="font-family: HelveticaNeue, Helvetica Neue,
Helvetica, Arial, Lucida Grande, sans-serif; font-size:
16px;">
<div dir="ltr"><font face="Arial" size="2"> On Friday,
July 15, 2016 6:07 AM, Kroshka Yenot
<a class="moz-txt-link-rfc2396E" href="mailto:trashbox@cary.lv"><trashbox@cary.lv></a> wrote:<br>
</font></div>
<br>
<br>
<div class="y_msg_container">
<div id="yiv5370434440">
<div>
<div>Hi!</div>
<div>if content type is 'application/json' or
'application/json; charset=utf-8' Catalyst sets
content length in chars, NOT IN BYTES and I'm
getting <br>
</div>
<div>{"id":1, "msg":"В Питере</div>
<div>if content type is 'text/html' Catalyst sets
content length in bytes (properly) and everything
works fine<br>
</div>
<div>Is there any workaround to configure this <span
class="yiv5370434440g-active-word
yiv5370434440js-active-word"><span
class="yiv5370434440translation">behaviour</span></span><span
class="yiv5370434440translation">, except
setting content length manually everytime ?</span><br>
</div>
<div><br>
</div>
<div>my $json_text = '{"id":1, "msg":"В Питере
пить"}';<br>
</div>
<div>$c->response->content_type('application/json');<br>
$c->response->content_length(bytes::length
$json_text);<br>
$c->response->body($json_text);<br>
</div>
<div>Thanks in advance<br>
</div>
<div><br>
</div>
</div>
</div>
<br>
_______________________________________________<br>
List: <a moz-do-not-send="true"
ymailto="mailto:Catalyst@lists.scsys.co.uk"
href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
Listinfo: <a moz-do-not-send="true"
href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst"
target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br>
Searchable archive: <a moz-do-not-send="true"
href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/"
target="_blank">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br>
Dev site: <a moz-do-not-send="true"
href="http://dev.catalyst.perl.org/" target="_blank">http://dev.catalyst.perl.org/</a><br>
<br>
<br>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
List: <a class="moz-txt-link-abbreviated" href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a>
Listinfo: <a class="moz-txt-link-freetext" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a>
Searchable archive: <a class="moz-txt-link-freetext" href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a>
Dev site: <a class="moz-txt-link-freetext" href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a>
</pre>
</blockquote>
<br>
</body>
</html>