File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ def __init__(
3737 tenant_id : t .Optional [int ] = None ,
3838 session : t .Optional [requests .Session ] = None ,
3939 api_domain : t .Optional [str ] = None ,
40+ proxies : t .Optional [t .Dict [str , str ]] = None ,
4041 _auth : AuthBase | None = None ,
4142 _enable_beta_features : bool = False ,
4243 ) -> None :
@@ -59,6 +60,8 @@ def __init__(
5960 self ._api_token : t .Optional [str ] = None
6061 self ._api_token_exp : t .Optional [datetime ] = None
6162 self ._session = session or self ._create_session ()
63+ if proxies is not None :
64+ self ._session .proxies .update (proxies )
6265
6366 @classmethod
6467 def from_env (cls ) -> "FlareApiClient" :
Original file line number Diff line number Diff line change 11from datetime import datetime
22
33import pytest
4+ import requests
45import requests_mock
56
67from packaging .version import Version
@@ -86,3 +87,31 @@ def test_backoff_max() -> None:
8687 retry = FlareApiClient ._create_retry ()
8788 assert hasattr (retry , "backoff_max" )
8889 assert retry .backoff_max == 15
90+
91+
92+ def test_proxies_applied_to_session () -> None :
93+ client = FlareApiClient (
94+ api_key = "test" ,
95+ proxies = {"https" : "http://proxy.corp.local:8080" },
96+ )
97+ assert client ._session .proxies ["https" ] == "http://proxy.corp.local:8080"
98+
99+
100+ def test_proxies_default_no_proxy () -> None :
101+ client = FlareApiClient (api_key = "test" )
102+ assert client ._session .proxies == {}
103+
104+
105+ def test_proxies_merge_with_user_session () -> None :
106+ session = requests .Session ()
107+ session .proxies ["http" ] = "http://existing-proxy:3128"
108+
109+ client = FlareApiClient (
110+ api_key = "test" ,
111+ session = session ,
112+ proxies = {"https" : "http://new-proxy:8080" },
113+ )
114+
115+ assert client ._session is session
116+ assert client ._session .proxies ["http" ] == "http://existing-proxy:3128"
117+ assert client ._session .proxies ["https" ] == "http://new-proxy:8080"
You can’t perform that action at this time.
0 commit comments