Skip to content

{client,config}: allow passing through additional httpx arguments #105

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

Merged
merged 1 commit into from
Aug 27, 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 featureflags/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def authenticate(self):
verify = self._config.tls_trusted_cas_file

client = Client(base_url=self._config.base_url, verify_ssl=verify,
raise_on_unexpected_status=True)
raise_on_unexpected_status=True, httpx_args=self._config.httpx_args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorten line length to get CI passing for flake8

Suggested change
raise_on_unexpected_status=True, httpx_args=self._config.httpx_args)
raise_on_unexpected_status=True,
httpx_args=self._config.httpx_args)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone ahead and merged this into a feature branch and I will make the change there.

body = AuthenticationRequest(api_key=self._sdk_key)
response = retryable_authenticate(client=client, body=body).parsed
self._auth_token = response.auth_token
Expand Down Expand Up @@ -206,7 +206,8 @@ def make_client(self, url, token, account_id, config):
client = AuthenticatedClient(
base_url=url,
token=token,
verify_ssl=verify
verify_ssl=verify,
httpx_args=self._config.httpx_args,
)
# Additional headers used to track usage
additional_headers = {
Expand Down
15 changes: 13 additions & 2 deletions featureflags/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Configuration is a base class that has default values that you can change
during the instance of the client class"""

from typing import Callable
from typing import Any, Callable, Dict

from .interface import Cache
from .lru_cache import LRUCache
Expand All @@ -28,7 +28,8 @@ def __init__(
enable_stream: bool = True,
enable_analytics: bool = True,
max_auth_retries: int = 10,
tls_trusted_cas_file: str = None
tls_trusted_cas_file: str = None,
httpx_args: Dict[str, Any] = None,
):
self.base_url = base_url
self.events_url = events_url
Expand All @@ -49,6 +50,9 @@ def __init__(
self.enable_analytics = enable_analytics
self.max_auth_retries = max_auth_retries
self.tls_trusted_cas_file = tls_trusted_cas_file
self.httpx_args = httpx_args
if self.httpx_args is None:
self.httpx_args = {}


default_config = Config()
Expand Down Expand Up @@ -106,3 +110,10 @@ def func(config: Config) -> None:
config.tls_trusted_cas_file = value

return func


def with_httpx_args(args: Dict[str, Any]) -> Callable:
def func(config: Config) -> None:
config.httpx_args.update(args)

return func
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy