Skip to content

Commit 4f61f23

Browse files
authored
Support gzip compression for adminapi requests (#390)
1 parent 14f29bc commit 4f61f23

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

adminapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
Copyright (c) 2025 InnoGames GmbH
44
"""
55

6-
VERSION = (4, 17, 1)
6+
VERSION = (4, 18, 0)

adminapi/request.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
Copyright (c) 2019 InnoGames GmbH
44
"""
5+
import gzip
56
import logging
67
import os
78
from hashlib import sha1
@@ -138,8 +139,12 @@ def send_request(endpoint, get_params=None, post_params=None):
138139
else:
139140
assert False # Cannot happen
140141

141-
return json.loads(response.read().decode())
142+
content_encoding = response.info().get('Content-Encoding')
143+
content = response.read()
144+
if content_encoding == 'gzip':
145+
content = gzip.decompress(content)
142146

147+
return json.loads(content)
143148

144149
def _build_request(endpoint, get_params, post_params, retry=1):
145150
"""Wrap request data in an urllib Request instance
@@ -157,6 +162,7 @@ def _build_request(endpoint, get_params, post_params, retry=1):
157162
timestamp = int(time.time())
158163
headers = {
159164
'Content-Encoding': 'application/x-json',
165+
'Accept-Encoding': 'gzip',
160166
'X-Timestamp': str(timestamp),
161167
'X-API-Version': '.'.join(str(v) for v in VERSION),
162168
}

0 commit comments

Comments
 (0)