Skip to content
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

Constrain which encodings are supported by response.text. #2892

Open
1 task done
tomchristie opened this issue Oct 13, 2023 · 0 comments · May be fixed by #2896
Open
1 task done

Constrain which encodings are supported by response.text. #2892

tomchristie opened this issue Oct 13, 2023 · 0 comments · May be fixed by #2896
Labels
enhancement New feature or request

Comments

@tomchristie
Copy link
Member


Currently when accessing response.text any installed codec may be loaded, depending on the Content-Type header of the response. This is problematic partly because not all codecs are text codecs. It also feels too open, as custom codecs might be installed with arbitrary behaviours.

May suggestion would be that we support the same set of encodings as the chromium browser... https://chromium.googlesource.com/chromium/chromium/+/refs/heads/trunk/chrome/browser/character_encoding.cc#36

We can effect this change by having a hardcoded set of supported codecs, here...

httpx/httpx/_utils.py

Lines 71 to 79 in e63b659

def is_known_encoding(encoding: str) -> bool:
"""
Return `True` if `encoding` is a known codec.
"""
try:
codecs.lookup(encoding)
except LookupError:
return False
return True

@tomchristie tomchristie added the enhancement New feature or request label Oct 13, 2023
@tomchristie tomchristie linked a pull request Oct 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant