@@ -131,7 +131,7 @@ def request(
131
131
headers ["Content-Type" ] = "application/json"
132
132
if query_params :
133
133
url += "?" + urlencode (query_params )
134
- if ( "Content-Type" not in headers ) or ( re .search ("json" , headers ["Content-Type" ], re .IGNORECASE ) ):
134
+ if "Content-Type" not in headers or re .search ("json" , headers ["Content-Type" ], re .IGNORECASE ):
135
135
request_body = None
136
136
if body is not None :
137
137
request_body = json .dumps (body )
@@ -194,7 +194,12 @@ def request(
194
194
# For `GET`, `HEAD`
195
195
else :
196
196
r = self .pool_manager .request (
197
- method , url , fields = query_params , preload_content = _preload_content , timeout = timeout , headers = headers
197
+ method ,
198
+ url ,
199
+ fields = query_params ,
200
+ preload_content = _preload_content ,
201
+ timeout = timeout ,
202
+ headers = headers ,
198
203
)
199
204
except urllib3 .exceptions .SSLError as e :
200
205
msg = "{0}\n {1}" .format (type (e ).__name__ , str (e ))
@@ -269,7 +274,21 @@ async def request(
269
274
(connection, read) timeouts.
270
275
"""
271
276
assert not post_params , "not supported for now"
272
- response = await self ._client .request (url , method , headers , query_params , body , timeouts = _request_timeout )
277
+ request_body = None
278
+ if (
279
+ "Content-Type" not in headers
280
+ or re .search ("json" , headers ["Content-Type" ], re .IGNORECASE )
281
+ and body is not None
282
+ ):
283
+ request_body = json .dumps (body )
284
+ if headers .get ("Content-Encoding" ) == "gzip" :
285
+ compress = zlib .compressobj (wbits = 16 + zlib .MAX_WBITS )
286
+ request_body = compress .compress (request_body .encode ("utf-8" )) + compress .flush ()
287
+ elif headers .get ("Content-Encoding" ) == "deflate" :
288
+ request_body = zlib .compress (request_body .encode ("utf-8" ))
289
+ response = await self ._client .request (
290
+ url , method , headers , query_params , request_body , timeouts = _request_timeout
291
+ )
273
292
274
293
if not 200 <= response .status_code <= 299 :
275
294
data = b""
0 commit comments