<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. &nbsp;I have another&nbsp;unicode issue I need to look at soonish so I try to see if we can get &nbsp;a test case for this. &nbsp;-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 &lt;trashbox@cary.lv&gt; 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">&gt;&gt;&gt; Looks like to a bug to me</div>
    <div id="yui_3_16_0_ym19_1_1469219342715_5471">tl;dr&nbsp;&nbsp; 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] &nbsp;&nbsp;&nbsp;&nbsp; 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">
      &nbsp;&nbsp;&nbsp; my ( $self, $c ) = @_;<br clear="none">
      <br clear="none">
      &nbsp;&nbsp;&nbsp; my $json_text = '{"id":1, "msg":"В Питере пить"}';<br clear="none">
      &nbsp;&nbsp;&nbsp; $c-&gt;response-&gt;content_type('application/json');<br clear="none">
      &nbsp;&nbsp;&nbsp; $c-&gt;response-&gt;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>&nbsp;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--&nbsp; <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">
      &nbsp; HTTP/1.0 200 OK<br clear="none">
      &nbsp; Date: Wed, 20 Jul 2016 10:56:18 GMT<br clear="none">
      &nbsp; Server: HTTP::Server::PSGI<br clear="none">
      &nbsp; Content-Type: application/json<br clear="none">
      &nbsp; X-Catalyst: 5.90106<br clear="none">
      &nbsp; 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--&nbsp; <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">
      &nbsp; HTTP/1.1 200 OK<br clear="none">
      &nbsp; Date: Wed, 20 Jul 2016 12:02:28 GMT<br clear="none">
      &nbsp; Server: Apache<br clear="none">
      &nbsp; Set-Cookie: lang=ru; path=/; expires=Thu, 20-Jul-2017 12:02:28
      GMT<br clear="none">
      &nbsp; Set-Cookie: sid=3b2b88c4106b5e06c0c24a5c3a513ccbcb939299;
      domain=domain.tld; path=/; expires=Wed, 20-Jul-2016 12:52:28 GMT;
      HttpOnly<br clear="none">
      &nbsp; X-Catalyst: 5.90106<br clear="none">
      &nbsp; Content-Length: 31<br clear="none">
      &nbsp; Keep-Alive: timeout=5, max=100<br clear="none">
      &nbsp; Connection: Keep-Alive<br clear="none">
      &nbsp; 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-&gt;response-&gt;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-&gt;stash-&gt;{msg} = "В Питере пить";<br clear="none">
      $c-&gt;stash-&gt;{id} = 1;<br clear="none">
      $c-&gt;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. &nbsp;I'm happy
          to get a patch, or at the very least give me a broken test
          case (checkout&nbsp;<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>&nbsp;</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">&lt;trashbox@cary.lv&gt;</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-&gt;response-&gt;content_type('application/json');<br clear="none">
                      $c-&gt;response-&gt;content_length(bytes::length
                      $json_text);<br clear="none">
                      $c-&gt;response-&gt;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>