<html><head></head><body><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_ym19_1_1469219342715_5480"><span id="yui_3_16_0_ym19_1_1469219342715_5686">So what it looks like to me is that the code that sets a content length if one is not set by the view is not dealing with unicode correctly. I have another unicode issue I need to look at soonish so I try to see if we can get a test case for this. -jnap</span></div> <div class="qtdSeparateBR" id="yui_3_16_0_ym19_1_1469219342715_5479"><br><br></div><div class="yahoo_quoted" id="yui_3_16_0_ym19_1_1469219342715_5476" style="display: block;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" id="yui_3_16_0_ym19_1_1469219342715_5475"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" id="yui_3_16_0_ym19_1_1469219342715_5474"> <div dir="ltr" id="yui_3_16_0_ym19_1_1469219342715_5478"><font size="2" face="Arial" id="yui_3_16_0_ym19_1_1469219342715_5477"> On Wednesday, July 20, 2016 8:18 AM, Kroshka Yenot <trashbox@cary.lv> wrote:<br></font></div> <br><br> <div class="y_msg_container" id="yui_3_16_0_ym19_1_1469219342715_5473"><div id="yiv3544209190"><div id="yui_3_16_0_ym19_1_1469219342715_5472">
<div id="yui_3_16_0_ym19_1_1469219342715_5491">>>> Looks like to a bug to me</div>
<div id="yui_3_16_0_ym19_1_1469219342715_5471">tl;dr I'm not sure its a Catalyst bug or problem. It's may be
MY configuration problem or standard violation<br clear="none">
</div>
<div id="yui_3_16_0_ym19_1_1469219342715_5482"><br clear="none">
</div>
<div id="yui_3_16_0_ym19_1_1469219342715_5481">Here are my investigation results<br clear="none">
</div>
<div><br clear="none">
</div>
<div>I created a test to reproduce this situation <br clear="none">
</div>
<div># catalyst.pl test</div>
<div># test/script/test_create.pl view HTML TT<br clear="none">
</div>
<div># [editor] test/lib/test/Controller/Root.pm<br clear="none">
</div>
<div id="yui_3_16_0_ym19_1_1469219342715_5492">sub index :Path :Args(0)<br clear="none">
{<br clear="none">
my ( $self, $c ) = @_;<br clear="none">
<br clear="none">
my $json_text = '{"id":1, "msg":"В Питере пить"}';<br clear="none">
$c->response->content_type('application/json');<br clear="none">
$c->response->body($json_text);<br clear="none">
}<br clear="none">
</div>
<div id="yui_3_16_0_ym19_1_1469219342715_5493"><br clear="none">
</div>
<div>and found following:<br clear="none">
</div>
<div><br clear="none">
</div>
<div> wget -S -O - <a rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-freetext" target="_blank" onclick="return theMainWindow.showLinkWarning(this)" href="http://domain.tld:3000/">http://domain.tld:3000</a><br clear="none">
--2016-07-20 13:56:18-- <a rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-freetext" target="_blank" onclick="return theMainWindow.showLinkWarning(this)" href="http://domain.tld:3000/">http://domain.tld:3000/</a><br clear="none">
Resolving cary.lv (cary.lv)... aaa.bbb.ccc.ddd<br clear="none">
Connecting to domain.tld (domain.tld)|aaa.bbb.ccc.ddd|:3000...
connected.<br clear="none">
HTTP request sent, awaiting response...<br clear="none">
HTTP/1.0 200 OK<br clear="none">
Date: Wed, 20 Jul 2016 10:56:18 GMT<br clear="none">
Server: HTTP::Server::PSGI<br clear="none">
Content-Type: application/json<br clear="none">
X-Catalyst: 5.90106<br clear="none">
Content-Length: 42<br clear="none">
Length: 42 [application/json]<br clear="none">
Saving to: 'STDOUT'<br clear="none">
</div>
<div><br clear="none">
</div>
<div>content-Length is properly set. I see same using Firefox Dev
tools<br clear="none">
</div>
<div>but in the log (build-in test server log)<br clear="none">
</div>
<div>[debug] Response Code: 200; Content-Type: application/json;
Content-Length: unknown<br clear="none">
</div>
<div><br clear="none">
</div>
<div>Exactly same code, but app works as fastcgi daemon and
Apache/2.4.23 (FreeBSD) serves http requests <br clear="none">
</div>
<div># wget -S -O - <a rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-freetext" target="_blank" href="http://domain.tld/">http://domain.tld/</a><br clear="none">
--2016-07-20 15:02:28-- <a rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-freetext" target="_blank" href="http://domain.tld/">http://domain.tld/</a><br clear="none">
Resolving domain.tld (domain.tld)... aaa.bbb.ccc.ddd<br clear="none">
Connecting to domain.tld (domain.tld)|aaa.bbb.ccc.ddd|:80...
connected.<br clear="none">
HTTP request sent, awaiting response...<br clear="none">
HTTP/1.1 200 OK<br clear="none">
Date: Wed, 20 Jul 2016 12:02:28 GMT<br clear="none">
Server: Apache<br clear="none">
Set-Cookie: lang=ru; path=/; expires=Thu, 20-Jul-2017 12:02:28
GMT<br clear="none">
Set-Cookie: sid=3b2b88c4106b5e06c0c24a5c3a513ccbcb939299;
domain=domain.tld; path=/; expires=Wed, 20-Jul-2016 12:52:28 GMT;
HttpOnly<br clear="none">
X-Catalyst: 5.90106<br clear="none">
Content-Length: 31<br clear="none">
Keep-Alive: timeout=5, max=100<br clear="none">
Connection: Keep-Alive<br clear="none">
Content-Type: application/json<br clear="none">
Length: 31 [application/json]<br clear="none">
</div>
<div><br clear="none">
</div>
<div>Content length here is in chars not in bytes<br clear="none">
</div>
<div>A solution by Aristotle Pagaltzis <br clear="none">
</div>
<div> $c->response->body(Encode::encode_utf8 $json_text);</div>
<div>gives proper content length in this situation<br clear="none">
</div>
<div>I'm getting same proper content length if I change content type
to 'text/html'</div>
<div><br clear="none">
</div>
<div>Finally, I've discovered Catalyst::View::JSON</div>
<div>and it not only solved this problem for me, but also gave me a
much more comfortable solution to work with json <br clear="none">
</div>
<div>$c->stash->{msg} = "В Питере пить";<br clear="none">
$c->stash->{id} = 1;<br clear="none">
$c->forward('View::JSON');<br clear="none">
</div>
<div>Works like a charm<br clear="none">
</div>
<div><br clear="none">
</div>
<div>Taking this opportunity, thank you for this lovely framework!</div>
<div>I'll be happy to provide any additional information if you still
consider there is something should be fixed<br clear="none">
</div>
<div><br clear="none">
</div>
<div><br clear="none">
</div>
<br clear="none">
<br clear="none">
<br clear="none">
<br clear="none">
<div class="yiv3544209190moz-cite-prefix">19.07.2016 19:10, John Napiorkowski
пишет:<br clear="none">
</div>
<blockquote type="cite">
<div class="yiv3544209190yqt2772912217" id="yiv3544209190yqt19218"><div style="color:#000;background-color:#fff;font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;">
<div dir="ltr" id="yiv3544209190yui_3_16_0_1_1468944360128_4375">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 rel="nofollow" shape="rect" class="yiv3544209190" id="yiv3544209190yui_3_16_0_1_1468944360128_4381" target="_blank" href="https://github.com/perl-catalyst/catalyst-runtime/blob/master/t/utf_incoming.t">https://github.com/perl-catalyst/catalyst-runtime/blob/master/t/utf_incoming.t</a> </div>
<div id="yiv3544209190yui_3_16_0_1_1468944360128_4452"><br clear="none">
</div>
<div dir="ltr" id="yiv3544209190yui_3_16_0_1_1468944360128_4452">and see if
you can help me figure it out -jnap</div>
<div dir="ltr" id="yiv3544209190yui_3_16_0_1_1468944360128_4452"><br clear="none">
</div>
<div dir="ltr" id="yiv3544209190yui_3_16_0_1_1468944360128_4452">(created an
issues for this, _<a rel="nofollow" shape="rect" class="yiv3544209190" id="yiv3544209190yui_3_16_0_1_1468944360128_5338" target="_blank" href="https://github.com/perl-catalyst/catalyst-runtime/issues/143">https://github.com/perl-catalyst/catalyst-runtime/issues/143</a></div>
<div id="yiv3544209190yui_3_16_0_1_1468944360128_5347"><br clear="none">
</div>
<div><br clear="none">
</div>
<div id="yiv3544209190yui_3_16_0_1_1468944360128_4390"><br clear="none">
</div>
<div class="yiv3544209190qtdSeparateBR"><br clear="none">
<br clear="none">
</div>
<div class="yiv3544209190yahoo_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 rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-rfc2396E" ymailto="mailto:trashbox@cary.lv" target="_blank" href="mailto:trashbox@cary.lv"><trashbox@cary.lv></a> wrote:<br clear="none">
</font></div>
<br clear="none">
<br clear="none">
<div class="yiv3544209190y_msg_container">
<div id="yiv3544209190">
<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 clear="none">
</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 clear="none">
</div>
<div>Is there any workaround to configure this <span class="yiv3544209190g-active-word yiv3544209190js-active-word"><span class="yiv3544209190translation">behaviour</span></span><span class="yiv3544209190translation">, except
setting content length manually everytime ?</span><br clear="none">
</div>
<div><br clear="none">
</div>
<div>my $json_text = '{"id":1, "msg":"В Питере
пить"}';<br clear="none">
</div>
<div>$c->response->content_type('application/json');<br clear="none">
$c->response->content_length(bytes::length
$json_text);<br clear="none">
$c->response->body($json_text);<br clear="none">
</div>
<div>Thanks in advance<br clear="none">
</div>
<div><br clear="none">
</div>
</div>
</div>
<br clear="none">
_______________________________________________<br clear="none">
List: <a rel="nofollow" shape="rect" ymailto="mailto:Catalyst@lists.scsys.co.uk" target="_blank" href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br clear="none">
Listinfo: <a rel="nofollow" shape="rect" target="_blank" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br clear="none">
Searchable archive: <a rel="nofollow" shape="rect" target="_blank" href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br clear="none">
Dev site: <a rel="nofollow" shape="rect" target="_blank" href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a><br clear="none">
<br clear="none">
<br clear="none">
</div>
</div>
</div>
</div>
</div></div>
<br clear="none">
<fieldset class="yiv3544209190mimeAttachmentHeader"></fieldset>
<br clear="none">
<pre>_______________________________________________
List: <a rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-abbreviated" ymailto="mailto:Catalyst@lists.scsys.co.uk" target="_blank" href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a>
Listinfo: <a rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-freetext" target="_blank" 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 rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-freetext" target="_blank" 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 rel="nofollow" shape="rect" class="yiv3544209190moz-txt-link-freetext" target="_blank" href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a>
</pre>
</blockquote>
<br clear="none">
</div></div><br><div class="yqt2772912217" id="yqt44924">_______________________________________________<br clear="none">List: <a shape="rect" ymailto="mailto:Catalyst@lists.scsys.co.uk" href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br clear="none">Listinfo: <a shape="rect" 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 clear="none">Searchable archive: <a shape="rect" 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 clear="none">Dev site: <a shape="rect" href="http://dev.catalyst.perl.org/" target="_blank">http://dev.catalyst.perl.org/</a><br clear="none"></div><br><br></div> </div> </div> </div></div></body></html>