diff --git a/openfga_sdk/configuration.py b/openfga_sdk/configuration.py index bc015d7..6ad6591 100644 --- a/openfga_sdk/configuration.py +++ b/openfga_sdk/configuration.py @@ -297,6 +297,9 @@ def __init__( self.proxy = None """Proxy URL """ + self.trust_env = True + """Whether the async HTTP client trusts environment proxy and netrc configuration. + """ self.proxy_headers = None """Proxy headers """ diff --git a/openfga_sdk/rest.py b/openfga_sdk/rest.py index 54090ae..034473c 100644 --- a/openfga_sdk/rest.py +++ b/openfga_sdk/rest.py @@ -164,7 +164,9 @@ def __init__( self.proxy = configuration.proxy self.proxy_headers = configuration.proxy_headers self._timeout_millisec = configuration.timeout_millisec - self.pool_manager = aiohttp.ClientSession(connector=connector, trust_env=True) + self.pool_manager = aiohttp.ClientSession( + connector=connector, trust_env=getattr(configuration, "trust_env", True) + ) # aiohttp 3.10+ resends GET, HEAD, PUT and DELETE once by itself when a # kept-alive connection drops. Turn that off, as aiohttp.test_utils does, # so retry_params and the resend count are exact; such a request then diff --git a/test/rest_test.py b/test/rest_test.py index 1f3a6fe..76aa460 100644 --- a/test/rest_test.py +++ b/test/rest_test.py @@ -52,6 +52,22 @@ def test_restresponse_getheader(): assert missing == "fallback" +@pytest.mark.asyncio +async def test_rest_client_passes_trust_env_to_aiohttp(monkeypatch): + from openfga_sdk.configuration import Configuration + + session = MagicMock() + client_session = MagicMock(return_value=session) + monkeypatch.setattr(aiohttp, "ClientSession", client_session) + + configuration = Configuration(api_url="http://example.com") + configuration.trust_env = False + + RESTClientObject(configuration=configuration) + + assert client_session.call_args.kwargs["trust_env"] is False + + @pytest.mark.asyncio async def test_build_request_json_body(): mock_config = MagicMock()