Skip to content

Commit

Permalink
feat: Proxy support (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored Sep 28, 2024
1 parent 2ca2e46 commit 8629f6f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions postgrest/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
headers: Dict[str, str] = DEFAULT_POSTGREST_CLIENT_HEADERS,
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
BasePostgrestClient.__init__(
self,
Expand All @@ -37,6 +38,7 @@ def __init__(
headers=headers,
timeout=timeout,
verify=verify,
proxy=proxy,
)
self.session = cast(AsyncClient, self.session)

Expand All @@ -46,12 +48,14 @@ def create_session(
headers: Dict[str, str],
timeout: Union[int, float, Timeout],
verify: bool = True,
proxy: Optional[str] = None,
) -> AsyncClient:
return AsyncClient(
base_url=base_url,
headers=headers,
timeout=timeout,
verify=verify,
proxy=proxy,
follow_redirects=True,
http2=True,
)
Expand Down
4 changes: 4 additions & 0 deletions postgrest/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
headers: Dict[str, str] = DEFAULT_POSTGREST_CLIENT_HEADERS,
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
BasePostgrestClient.__init__(
self,
Expand All @@ -37,6 +38,7 @@ def __init__(
headers=headers,
timeout=timeout,
verify=verify,
proxy=proxy,
)
self.session = cast(SyncClient, self.session)

Expand All @@ -46,12 +48,14 @@ def create_session(
headers: Dict[str, str],
timeout: Union[int, float, Timeout],
verify: bool = True,
proxy: Optional[str] = None,
) -> SyncClient:
return SyncClient(
base_url=base_url,
headers=headers,
timeout=timeout,
verify=verify,
proxy=proxy,
follow_redirects=True,
http2=True,
)
Expand Down
4 changes: 3 additions & 1 deletion postgrest/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ def __init__(
headers: Dict[str, str],
timeout: Union[int, float, Timeout],
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
headers = {
**headers,
"Accept-Profile": schema,
"Content-Profile": schema,
}
self.session = self.create_session(base_url, headers, timeout, verify)
self.session = self.create_session(base_url, headers, timeout, verify, proxy)

@abstractmethod
def create_session(
Expand All @@ -34,6 +35,7 @@ def create_session(
headers: Dict[str, str],
timeout: Union[int, float, Timeout],
verify: bool = True,
proxy: Optional[str] = None,
) -> Union[SyncClient, AsyncClient]:
raise NotImplementedError()

Expand Down

0 comments on commit 8629f6f

Please sign in to comment.