Skip to content

Commit e5fffb6

Browse files
committed
python-ecosys/aiohttp: Fix header case sensi.
Signed-off-by: FuNK3Y
1 parent 65a1411 commit e5fffb6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

python-ecosys/aiohttp/aiohttp/__init__.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ class ClientResponse:
1818
def __init__(self, reader):
1919
self.content = reader
2020

21+
def get_header(self, keyname, value=None):
22+
try:
23+
return next((v for k, v in self.headers.items() if k.lower() == keyname.lower()))
24+
except StopIteration:
25+
return value
26+
2127
def _decode(self, data):
22-
c_encoding = self.headers.get("Content-Encoding")
28+
c_encoding = self.get_header("Content-Encoding")
2329
if c_encoding in ("gzip", "deflate", "gzip,deflate"):
2430
try:
2531
import deflate
@@ -39,10 +45,10 @@ async def read(self, sz=-1):
3945
return self._decode(await self.content.read(sz))
4046

4147
async def text(self, encoding="utf-8"):
42-
return (await self.read(int(self.headers.get("Content-Length", -1)))).decode(encoding)
48+
return (await self.read(int(self.get_header("Content-Length", -1)))).decode(encoding)
4349

4450
async def json(self):
45-
return _json.loads(await self.read(int(self.headers.get("Content-Length", -1))))
51+
return _json.loads(await self.read(int(self.get_header("Content-Length", -1))))
4652

4753
def __repr__(self):
4854
return "<ClientResponse %d %s>" % (self.status, self.headers)

0 commit comments

Comments
 (0)