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

Add proxy support #479

Merged
merged 9 commits into from
Dec 12, 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
5 changes: 3 additions & 2 deletions src/solana/rpc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Client(_ClientCore): # pylint: disable=too-many-public-methods
commitment: Default bank state to query. It can be either "finalized", "confirmed" or "processed".
timeout: HTTP request timeout in seconds.
extra_headers: Extra headers to pass for HTTP request.

proxy: Proxy URL to pass to the HTTP client.
"""

def __init__(
Expand All @@ -92,10 +92,11 @@ def __init__(
commitment: Optional[Commitment] = None,
timeout: float = 10,
extra_headers: Optional[Dict[str, str]] = None,
proxy: Optional[str] = None,
):
"""Init API client."""
super().__init__(commitment)
self._provider = http.HTTPProvider(endpoint, timeout=timeout, extra_headers=extra_headers)
self._provider = http.HTTPProvider(endpoint, timeout=timeout, extra_headers=extra_headers, proxy=proxy)

def is_connected(self) -> bool:
"""Health check.
Expand Down
6 changes: 5 additions & 1 deletion src/solana/rpc/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class AsyncClient(_ClientCore): # pylint: disable=too-many-public-methods
commitment: Default bank state to query. It can be either "finalized", "confirmed" or "processed".
timeout: HTTP request timeout in seconds.
extra_headers: Extra headers to pass for HTTP request.
proxy: Proxy URL to pass to the HTTP client.
"""

def __init__(
Expand All @@ -88,10 +89,13 @@ def __init__(
commitment: Optional[Commitment] = None,
timeout: float = 10,
extra_headers: Optional[Dict[str, str]] = None,
proxy: Optional[str] = None,
) -> None:
"""Init API client."""
super().__init__(commitment)
self._provider = async_http.AsyncHTTPProvider(endpoint, timeout=timeout, extra_headers=extra_headers)
self._provider = async_http.AsyncHTTPProvider(
endpoint, timeout=timeout, extra_headers=extra_headers, proxy=proxy
)

async def __aenter__(self) -> "AsyncClient":
"""Use as a context manager."""
Expand Down
3 changes: 2 additions & 1 deletion src/solana/rpc/providers/async_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ def __init__(
endpoint: Optional[str] = None,
extra_headers: Optional[Dict[str, str]] = None,
timeout: float = DEFAULT_TIMEOUT,
proxy: Optional[str] = None,
):
"""Init AsyncHTTPProvider."""
super().__init__(endpoint, extra_headers)
self.session = httpx.AsyncClient(timeout=timeout)
self.session = httpx.AsyncClient(timeout=timeout, proxy=proxy)

def __str__(self) -> str:
"""String definition for HTTPProvider."""
Expand Down
3 changes: 2 additions & 1 deletion src/solana/rpc/providers/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ def __init__(
endpoint: Optional[str] = None,
extra_headers: Optional[Dict[str, str]] = None,
timeout: float = DEFAULT_TIMEOUT,
proxy: Optional[str] = None,
):
"""Init HTTPProvider."""
super().__init__(endpoint, extra_headers)
self.session = httpx.Client(timeout=timeout)
self.session = httpx.Client(timeout=timeout, proxy=proxy)

def __str__(self) -> str:
"""String definition for HTTPProvider."""
Expand Down
Loading