Skip to content

Commit 7b2f636

Browse files
committed
Fix templates
1 parent 2728b6d commit 7b2f636

File tree

2 files changed

+17
-8
lines changed
  • .generator/src/generator/templates
  • src/datadog_api_client

2 files changed

+17
-8
lines changed

.generator/src/generator/templates/rest.j2

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class RESTClientObject:
129129
headers["Content-Type"] = "application/json"
130130
if query_params:
131131
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):
133133
request_body = None
134134
if body is not None:
135135
request_body = json.dumps(body)
@@ -267,7 +267,21 @@ class AsyncRESTClientObject:
267267
(connection, read) timeouts.
268268
"""
269269
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+
)
271285

272286
if not 200 <= response.status_code <= 299:
273287
data = b""

src/datadog_api_client/rest.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,7 @@ def request(
194194
# For `GET`, `HEAD`
195195
else:
196196
r = self.pool_manager.request(
197-
method,
198-
url,
199-
fields=query_params,
200-
preload_content=_preload_content,
201-
timeout=timeout,
202-
headers=headers,
197+
method, url, fields=query_params, preload_content=_preload_content, timeout=timeout, headers=headers
203198
)
204199
except urllib3.exceptions.SSLError as e:
205200
msg = "{0}\n{1}".format(type(e).__name__, str(e))

0 commit comments

Comments
 (0)