-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
No charset in json response - revisted #1631
Comments
That is expected. Valid JSON should always be in utf-8 and served with a proper header. |
@samdark Exactly. And for that reason you should explicitly set it to UTF-8. Currently my json response without that fix will not return as proper UTF-8! |
OK, adding a header explicitly won't hurt. |
Sounds reasonable and would be extremely helpful.... |
Please check the comment for the reason why the charset header is dropped: 595ac6d#commitcomment-3988192 |
I saw that change. But that was the application char set. Here it would be a fixed UTF-8 char set header. |
How does the header look like? |
HTTP/1.1 200 OK |
I don't see the charset header. |
There is no charset header in my output! |
I was asking what charset header you are expecting... |
I start to see your point: for Content-Type: application/json there is no charset parameter.... However, only when I add the charset parameter my browser (firefox) shows the data correctly as UTF-8 encoded. At least in some occasions. But it works for me now and so a tend to agree that the code is correct. |
I guess it's related with browser. I'm closing this one unless we see other reports of similar problem. Thanks. |
@qiangxue it's fine to be left opened till I'll fix it (github push problems currently). Header is |
Is there such a header |
I also don't quite understand the use case you described "It's not an issue if you serve all the content with utf-8 but can be a problem if all the content is, for example, uses cp1251 but some URLs are serving JSON which should be utf-8." Do you mean some responses use cp1251 while some use JSON/UTF-8? Why does this case matter here? |
No, I've meant So sitewide you're using 1251 for responses but JSON can't be served with anything other than UTF-8. That's why we're sending our own header overriding server config. |
I see. I'm fine adding it back then. |
I think it does not do harm to add it but I think according to spec Content-Type: application/json does not have an optional parameter charset. Only e.g. html has it (see http://www.iana.org/assignments/media-types/text/html) But again: I do not think it does harm but sometimes it even seems to help certain browsers (see my remarks above). So I would added it but maybe put a comment in explaining why we did it. |
* upstream: (35 commits) Fixes yiisoft#1691: added “viewport” meta tag to layout views. Fixed the issue that query cache returns the same data for the same SQL but different query methods moved section subsection added typo [skip ci] docs about response Fixes yiisoft#1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default docs improved csrf docs added Fixes yiisoft#1685: UrlManager::showScriptName should be set true for tests. Fixes yiisoft#1688: ActiveForm is creating duplicated messages in error summary change back the visibility of findTableNames to protected. Typo fix. Fixes yiisoft#1681: Added support for automatically adjusting the "for" attribute of label generated by `ActiveField::label()` Simplified tests. Fixes yiisoft#1631: Charset is now explicitly set to UTF-8 when serving JSON Fixed typo added html layout for mail component in basic app CS fixes. Merge branch 'debug_module_improvements' of github.com:Ragazzo/yii2 into Ragazzo-debug_module_improvements ...
In #833 the support has been introduced and then has been dropped again since only UTF-8 as char set is correct.
Currently, not working for me. The response was not UTF-8 and I needed to explicitly add the UTF8 as charset in the header.
The text was updated successfully, but these errors were encountered: