httpx icon indicating copy to clipboard operation
httpx copied to clipboard

Constrain which encodings are supported by `response.text`.

Open lovelydinosaur opened this issue 2 years ago • 0 comments
trafficstars

  • [x] Initially raised as discussion #2881

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...

https://github.com/encode/httpx/blob/e63b6594f2863b7c8274eb0991ebc6cad63661f7/httpx/_utils.py#L71-L79

lovelydinosaur avatar Oct 13 '23 12:10 lovelydinosaur