Skip to content

Commit

Permalink
httpx -> requests
Browse files Browse the repository at this point in the history
  • Loading branch information
matveyvarg committed Aug 22, 2024
1 parent 0bc8e81 commit 5b0969d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
14 changes: 8 additions & 6 deletions deker_server_adapters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class AdaptersFactory(BaseAdaptersFactory):
def __init__(self, ctx: "CTX", uri: "Uri") -> None:
# Make base url, so all urls will be relative
kwargs = {
"base_url": uri.raw_url,
"verify": True,
"http2": False,
"timeout": None,
# "base_url": uri.raw_url,
# "verify": True,
# "http2": False,
# "timeout": None,
}

# If Uri contains auth params, remember them
if uri.username:
kwargs.update({"auth": (uri.username, uri.password)})
# if uri.username:
# kwargs.update({"auth": (uri.username, uri.password)})

# update values from context kwargs
kwargs.update(ctx.extra.get("httpx_conf", {}))
Expand All @@ -47,6 +47,8 @@ def __init__(self, ctx: "CTX", uri: "Uri") -> None:
)

self.httpx_client = HttpxClient(**kwargs)
self.httpx_client.base_url = uri.raw_url
self.httpx_client.auth = (uri.username, uri.password)
# We have to keep reference to ctx, to be able to set new configuration
self.httpx_client.ctx = copied_ctx
copied_ctx.extra["httpx_client"] = self.httpx_client
Expand Down
4 changes: 3 additions & 1 deletion deker_server_adapters/httpx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from deker.ctx import CTX
from deker.errors import DekerMemoryError
from httpx import Client, Response
from requests import Session

from deker_server_adapters.cluster_config import apply_config
from deker_server_adapters.consts import (
Expand Down Expand Up @@ -44,7 +45,7 @@ def rate_limit_err(response: Response, message: str, class_: Type[DekerBaseRateL
)


class HttpxClient(Client):
class HttpxClient(Session):
"""Wrapper around HttpxClient."""

ctx: CTX
Expand All @@ -57,6 +58,7 @@ def request(self, *args: Any, retry_on_hash_failure: bool = False, **kwargs: Any
:param retry_on_hash_failure: If we should retry on invalid hash
:param kwargs: keyword arguments to request
"""
kwargs["timeout"] = None
response = super().request(*args, **kwargs)
if response.status_code == CONFLICT_HASH:
apply_config(response.json(), self.ctx)
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ priority = "supplemental"
python = "^3.9"
httpx = "^0.27.0"
pytest-httpx = "^0.30.0"
requests = "^2.32.3"

[tool.poetry.group.dev.dependencies]
black = "^23.7.0"
Expand Down

0 comments on commit 5b0969d

Please sign in to comment.