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
Using encodings other than UTF-8 in Response #1005
Comments
Why would you want any other encoding for text? |
@ThiefMaster My original intention was not emitting the charset header at all, cause we have many legacy documents written in the encoding other than UTF-8. So until we convert them to the unified format, I was to let the client choose the encoding by itself. |
I think converting them is a better idea. Letting the client choose the charset is a bad idea - chances are good it'll get it wrong and show it as gibberish. I guess all of your documents have the same charset? If yes it shouldn't be too hard to convert them! |
@ThiefMaster Currently at least the two encodings(cp949, cp932) are used, which are so similar that I cannot make an automated converter, because the text in one encoding does not cause UnicodeDecodeError when decoded by the other encoding... The only way to determine the encoding is using |
To summarize:
Maybe adding a check for (pushed these to override-response-charset) |
Going to close this in favor of the options in the previous comment. |
The Flask documentation states that Flask assumes the encoding of the response to be UTF-8.
Does that mean we are discouraged to use the encodings other than UTF-8 in the Flask response? I was unable to find a way to change the intended encoding of neither
flask.wrappers.Response
norwerkzeug.wrappers.Response
correctly.charset
parameter. There is no way to change its behavior. So I should create the response object with no constructor arguments, and then assign 'utf-8' toresponse.charset
, and callresponse.set_data()
.content_type
is determined in the constructor, it will still be "text/html; charset=UTF-8" because thecharset
attribute is always'utf-8'
during the object creation process. So I'm forced to passcontent_type
to the constructor, which is kinda confusing because my original intention was just changing the encoding, rather than explicitly setting the Content-Type.Do I understand the process accurately?
If I'm right, I suggest:
charset
to theResponse
class.content_type
attribute should be updated again when the user manually sets thecharset
attribute.The text was updated successfully, but these errors were encountered: