Add 'decode_content' argument to the top level request method
MODIFY
src/urllib3/__init__.py
src/urllib3/__init__.py
@@ -96,6 +96,7 @@ def request(
fields: Optional[_TYPE_FIELDS] = None,
headers: Optional[Mapping[str, str]] = None,
preload_content: Optional[bool] = True,
+ decode_content: Optional[bool] = True,
redirect: Optional[bool] = True,
retries: Optional[Union[Retry, bool, int]] = None,
timeout: Optional[Union[Timeout, float, int]] = 3,
@@ -114,6 +115,7 @@ def request(
fields=fields,
headers=headers,
preload_content=preload_content,
+ decode_content=decode_content,
redirect=redirect,
retries=retries,
timeout=timeout,

MODIFY
test/with_dummyserver/test_poolmanager.py
test/with_dummyserver/test_poolmanager.py
+import gzip
import json
from test import LONG_TIMEOUT
from unittest import mock
@@ -424,6 +425,25 @@ class TestPoolManager(HTTPDummyServerTestCase):
r.data
assert r.connection is None
+ def test_top_level_request_with_decode_content(self):
+ r = request(
+ "GET",
+ f"{self.base_url}/encodingrequest",
+ headers={"accept-encoding": "gzip"},
+ decode_content=False,
+ )
+ assert r.status == 200
+ assert gzip.decompress(r.data) == b"hello, world!"
+
+ r = request(
+ "GET",
+ f"{self.base_url}/encodingrequest",
+ headers={"accept-encoding": "gzip"},
+ decode_content=True,
+ )
+ assert r.status == 200
+ assert r.data == b"hello, world!"
+
def test_top_level_request_with_redirect(self):
r = request(
"GET",
@@ -466,6 +486,7 @@ class TestPoolManager(HTTPDummyServerTestCase):
fields=None,
headers=None,
preload_content=True,
+ decode_content=True,
redirect=True,
retries=None,
timeout=2.5,

Add 'decode_content' argument to the top level request method