Add OxiAdapter for enhanced HTTP request handling in OxiAPI
- Introduced a new `OxiAdapter` class that extends `HTTPAdapter` to manage timeouts and retries for HTTP requests. - Integrated the `OxiAdapter` into the `OxiAPI` class, setting a default timeout and enabling retry logic for both HTTP and HTTPS requests.
This commit is contained in:
21
oxi/adapter.py
Normal file
21
oxi/adapter.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from typing import Optional
|
||||
from requests.adapters import HTTPAdapter
|
||||
from urllib3.util import Retry
|
||||
|
||||
|
||||
class OxiAdapter(HTTPAdapter):
|
||||
def __init__(
|
||||
self,
|
||||
timeout: Optional[int] = None,
|
||||
max_retries: int = 3,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
self.timeout = timeout
|
||||
retry = Retry(total=max_retries, backoff_factor=0.3)
|
||||
super().__init__(*args, max_retries=retry, **kwargs)
|
||||
|
||||
def send(self, request, **kwargs):
|
||||
if kwargs.get("timeout") is None:
|
||||
kwargs["timeout"] = self.timeout
|
||||
return super().send(request, **kwargs)
|
||||
Reference in New Issue
Block a user