@@ -129,7 +129,7 @@ class RESTClientObject:
129
129
headers["Content-Type"] = "application/json"
130
130
if query_params:
131
131
url += "?" + urlencode(query_params)
132
- if ( "Content-Type" not in headers) or ( re.search("json", headers["Content-Type"], re.IGNORECASE) ):
132
+ if "Content-Type" not in headers or re.search("json", headers["Content-Type"], re.IGNORECASE):
133
133
request_body = None
134
134
if body is not None:
135
135
request_body = json.dumps(body)
@@ -267,7 +267,21 @@ class AsyncRESTClientObject:
267
267
(connection, read) timeouts.
268
268
"""
269
269
assert not post_params, "not supported for now"
270
- response = await self._client.request(url, method, headers, query_params, body, timeouts=_request_timeout)
270
+ request_body = None
271
+ if (
272
+ "Content-Type" not in headers
273
+ or re.search("json", headers["Content-Type"], re.IGNORECASE)
274
+ and body is not None
275
+ ):
276
+ request_body = json.dumps(body)
277
+ if headers.get("Content-Encoding") == "gzip":
278
+ compress = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
279
+ request_body = compress.compress(request_body.encode("utf-8")) + compress.flush()
280
+ elif headers.get("Content-Encoding") == "deflate":
281
+ request_body = zlib.compress(request_body.encode("utf-8"))
282
+ response = await self._client.request(
283
+ url, method, headers, query_params, request_body, timeouts=_request_timeout
284
+ )
271
285
272
286
if not 200 <= response.status_code <= 299:
273
287
data = b""
0 commit comments