Skip to content

Commit

Permalink
feat: Proxy support (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored Sep 28, 2024
1 parent 3560683 commit 59d733a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions storage3/_async/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import Optional

from storage3.constants import DEFAULT_TIMEOUT

from ..utils import AsyncClient
Expand All @@ -21,21 +23,28 @@ def __init__(
headers: dict[str, str],
timeout: int = DEFAULT_TIMEOUT,
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
headers = {
"User-Agent": f"supabase-py/storage3 v{__version__}",
**headers,
}
self.session = self._create_session(url, headers, timeout, verify)
self.session = self._create_session(url, headers, timeout, verify, proxy)
super().__init__(self.session)

def _create_session(
self, base_url: str, headers: dict[str, str], timeout: int, verify: bool = True
self,
base_url: str,
headers: dict[str, str],
timeout: int,
verify: bool = True,
proxy: Optional[str] = None,
) -> AsyncClient:
return AsyncClient(
base_url=base_url,
headers=headers,
timeout=timeout,
proxy=proxy,
verify=bool(verify),
follow_redirects=True,
http2=True,
Expand Down
13 changes: 11 additions & 2 deletions storage3/_sync/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import Optional

from storage3.constants import DEFAULT_TIMEOUT

from ..utils import SyncClient
Expand All @@ -21,21 +23,28 @@ def __init__(
headers: dict[str, str],
timeout: int = DEFAULT_TIMEOUT,
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
headers = {
"User-Agent": f"supabase-py/storage3 v{__version__}",
**headers,
}
self.session = self._create_session(url, headers, timeout, verify)
self.session = self._create_session(url, headers, timeout, verify, proxy)
super().__init__(self.session)

def _create_session(
self, base_url: str, headers: dict[str, str], timeout: int, verify: bool = True
self,
base_url: str,
headers: dict[str, str],
timeout: int,
verify: bool = True,
proxy: Optional[str] = None,
) -> SyncClient:
return SyncClient(
base_url=base_url,
headers=headers,
timeout=timeout,
proxy=proxy,
verify=bool(verify),
follow_redirects=True,
http2=True,
Expand Down

0 comments on commit 59d733a

Please sign in to comment.