Skip to content

Commit 5eb8f0b

Browse files
committed
✨ add httpx transport config
1 parent 18ed668 commit 5eb8f0b

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

githubkit/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Config:
2424
ssl_verify: Union[bool, "ssl.SSLContext"]
2525
trust_env: bool # effects the `httpx` proxy and ssl cert
2626
proxy: Optional[ProxyTypes]
27+
transport: Optional[httpx.BaseTransport]
28+
async_transport: Optional[httpx.AsyncBaseTransport]
2729
cache_strategy: BaseCacheStrategy
2830
http_cache: bool
2931
throttler: BaseThrottler
@@ -113,6 +115,8 @@ def get_config(
113115
ssl_verify: Union[bool, "ssl.SSLContext"] = True,
114116
trust_env: bool = True,
115117
proxy: Optional[ProxyTypes] = None,
118+
transport: Optional[httpx.BaseTransport] = None,
119+
async_transport: Optional[httpx.AsyncBaseTransport] = None,
116120
cache_strategy: Optional[BaseCacheStrategy] = None,
117121
http_cache: bool = True,
118122
throttler: Optional[BaseThrottler] = None,
@@ -129,6 +133,8 @@ def get_config(
129133
ssl_verify,
130134
trust_env,
131135
proxy,
136+
transport,
137+
async_transport,
132138
build_cache_strategy(cache_strategy),
133139
http_cache,
134140
build_throttler(throttler),

githubkit/core.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def __init__(
8888
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
8989
trust_env: bool = True,
9090
proxy: Optional[ProxyTypes] = None,
91+
transport: Optional[httpx.BaseTransport] = None,
92+
async_transport: Optional[httpx.AsyncBaseTransport] = None,
9193
cache_strategy: Optional[BaseCacheStrategy] = None,
9294
http_cache: bool = True,
9395
throttler: Optional[BaseThrottler] = None,
@@ -110,6 +112,8 @@ def __init__(
110112
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
111113
trust_env: bool = True,
112114
proxy: Optional[ProxyTypes] = None,
115+
transport: Optional[httpx.BaseTransport] = None,
116+
async_transport: Optional[httpx.AsyncBaseTransport] = None,
113117
cache_strategy: Optional[BaseCacheStrategy] = None,
114118
http_cache: bool = True,
115119
throttler: Optional[BaseThrottler] = None,
@@ -132,6 +136,8 @@ def __init__(
132136
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
133137
trust_env: bool = True,
134138
proxy: Optional[ProxyTypes] = None,
139+
transport: Optional[httpx.BaseTransport] = None,
140+
async_transport: Optional[httpx.AsyncBaseTransport] = None,
135141
cache_strategy: Optional[BaseCacheStrategy] = None,
136142
http_cache: bool = True,
137143
throttler: Optional[BaseThrottler] = None,
@@ -153,6 +159,8 @@ def __init__(
153159
ssl_verify: Union[bool, "ssl.SSLContext"] = True,
154160
trust_env: bool = True,
155161
proxy: Optional[ProxyTypes] = None,
162+
transport: Optional[httpx.BaseTransport] = None,
163+
async_transport: Optional[httpx.AsyncBaseTransport] = None,
156164
cache_strategy: Optional[BaseCacheStrategy] = None,
157165
http_cache: bool = True,
158166
throttler: Optional[BaseThrottler] = None,
@@ -174,6 +182,8 @@ def __init__(
174182
ssl_verify=ssl_verify,
175183
trust_env=trust_env,
176184
proxy=proxy,
185+
transport=transport,
186+
async_transport=async_transport,
177187
cache_strategy=cache_strategy,
178188
http_cache=http_cache,
179189
throttler=throttler,
@@ -241,11 +251,14 @@ def _create_sync_client(self) -> httpx.Client:
241251
if self.config.http_cache:
242252
return hishel.CacheClient(
243253
**self._get_client_defaults(),
254+
transport=self.config.transport,
244255
storage=self.config.cache_strategy.get_hishel_storage(),
245256
controller=self.config.cache_strategy.get_hishel_controller(),
246257
)
247258

248-
return httpx.Client(**self._get_client_defaults())
259+
return httpx.Client(
260+
**self._get_client_defaults(), transport=self.config.transport
261+
)
249262

250263
# get or create sync client
251264
@contextmanager
@@ -263,11 +276,14 @@ def _create_async_client(self) -> httpx.AsyncClient:
263276
if self.config.http_cache:
264277
return hishel.AsyncCacheClient(
265278
**self._get_client_defaults(),
279+
transport=self.config.async_transport,
266280
storage=self.config.cache_strategy.get_async_hishel_storage(),
267281
controller=self.config.cache_strategy.get_hishel_controller(),
268282
)
269283

270-
return httpx.AsyncClient(**self._get_client_defaults())
284+
return httpx.AsyncClient(
285+
**self._get_client_defaults(), transport=self.config.async_transport
286+
)
271287

272288
# get or create async client
273289
@asynccontextmanager

githubkit/github.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def __init__(
7979
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
8080
trust_env: bool = True,
8181
proxy: Optional[ProxyTypes] = None,
82+
transport: Optional[httpx.BaseTransport] = None,
83+
async_transport: Optional[httpx.AsyncBaseTransport] = None,
8284
cache_strategy: Optional["BaseCacheStrategy"] = None,
8385
http_cache: bool = True,
8486
throttler: Optional["BaseThrottler"] = None,
@@ -101,6 +103,8 @@ def __init__(
101103
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
102104
trust_env: bool = True,
103105
proxy: Optional[ProxyTypes] = None,
106+
transport: Optional[httpx.BaseTransport] = None,
107+
async_transport: Optional[httpx.AsyncBaseTransport] = None,
104108
cache_strategy: Optional["BaseCacheStrategy"] = None,
105109
http_cache: bool = True,
106110
throttler: Optional["BaseThrottler"] = None,
@@ -123,6 +127,8 @@ def __init__(
123127
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
124128
trust_env: bool = True,
125129
proxy: Optional[ProxyTypes] = None,
130+
transport: Optional[httpx.BaseTransport] = None,
131+
async_transport: Optional[httpx.AsyncBaseTransport] = None,
126132
cache_strategy: Optional["BaseCacheStrategy"] = None,
127133
http_cache: bool = True,
128134
throttler: Optional["BaseThrottler"] = None,

0 commit comments

Comments
 (0)