Skip to content

Commit

Permalink
Add proxy support (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonney authored Dec 12, 2024
1 parent a5434bc commit 30e5e70
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
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

0 comments on commit 30e5e70

Please sign in to comment.