-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incorrect length in JSON? #143
Comments
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 https://github.com/perl-catalyst/catalyst-runtime/blob/master/t/utf_incoming.t and see if you can help me figure it out -jnap |
If you ask me, this is not a bug. application/json is not encoded by catalyst (as per doc) so it must be encoded to bytes before setting the body. Most serializers do that, so the wrong behavior here is just because of the manual json creation. |
@melmothx good catch, you'd think I'd remember that since I wrote the doc and made that call for back compat reasons. I wonder if the docs could not be more obvious and maybe I should add a config setting to 'force_json_encode_always' for people that are rolling their own... I guess I was thinking if you are doing that yourself I assume you know what you are doing... |
I'm thinking the docs should at least recommend one considers setting content length in your custom view, just to be safe. |
John Napiorkowski [email protected] writes:
I believe that if the string is passed correctly, the content length is Marco |
Hi!
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
{"id":1, "msg":"В Питере
if content type is 'text/html' Catalyst sets content length in bytes (properly) and everything works fine
Is there any workaround to configure this behaviour, except setting content length manually everytime ?
my $json_text = '{"id":1, "msg":"В Питере пить"}';
$c->response->content_type('application/json');
$c->response->content_length(bytes::length $json_text);
$c->response->body($json_text);
Thanks in advance
The text was updated successfully, but these errors were encountered: