Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Proxy support #297

Merged
merged 6 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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