finalsa-common-http-client 0.0.6__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/PKG-INFO +1 -1
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/finalsa/http/_shared.py +1 -1
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/finalsa/http/async_client/base.py +13 -2
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/finalsa/http/sync_client/base.py +1 -1
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/pyproject.toml +1 -1
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/.gitignore +0 -0
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/LICENSE.md +0 -0
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/README.md +0 -0
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/finalsa/http/__init__.py +0 -0
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/finalsa/http/async_client/__init__.py +0 -0
- {finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/finalsa/http/sync_client/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: finalsa-common-http-client
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Summary: HTTP client library for common data types used in business applications
|
|
5
5
|
Project-URL: Homepage, https://github.com/finalsa/finalsa-http-client
|
|
6
6
|
Project-URL: Documentation, https://github.com/finalsa/finalsa-http-client#readme
|
{finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/finalsa/http/_shared.py
RENAMED
|
@@ -21,7 +21,7 @@ class InternalHttpError(BaseDomainException):
|
|
|
21
21
|
|
|
22
22
|
def __init__(self, response_code: int | None = None):
|
|
23
23
|
super().__init__(
|
|
24
|
-
message="Internal HTTP error",
|
|
24
|
+
message=f"Internal HTTP error: {response_code}",
|
|
25
25
|
response_code=response_code or self.response_code,
|
|
26
26
|
name="InternalHttpError"
|
|
27
27
|
)
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import ssl
|
|
3
4
|
from collections.abc import Mapping
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
6
7
|
import aiohttp
|
|
8
|
+
import certifi
|
|
7
9
|
from aiohttp import ClientSession, ClientTimeout
|
|
8
10
|
|
|
9
11
|
from finalsa.http import _shared as shared
|
|
10
12
|
|
|
13
|
+
ssl_ctx = ssl.create_default_context(cafile=certifi.where())
|
|
14
|
+
|
|
11
15
|
|
|
12
16
|
class BaseAsyncHttpClient:
|
|
13
17
|
"""Reusable aiohttp-based HTTP client with sane defaults."""
|
|
@@ -27,6 +31,7 @@ class BaseAsyncHttpClient:
|
|
|
27
31
|
service_name: str = "finalsa-http-client",
|
|
28
32
|
trust_env: bool = False,
|
|
29
33
|
session: ClientSession | None = None,
|
|
34
|
+
raise_for_status: bool = True,
|
|
30
35
|
) -> None:
|
|
31
36
|
self._default_scheme = default_scheme
|
|
32
37
|
self.base_url = shared.normalize_base_url(base_url, default_scheme)
|
|
@@ -39,6 +44,7 @@ class BaseAsyncHttpClient:
|
|
|
39
44
|
default_headers,
|
|
40
45
|
service_name,
|
|
41
46
|
)
|
|
47
|
+
self._raise_for_status = raise_for_status
|
|
42
48
|
|
|
43
49
|
async def __aenter__(self) -> BaseAsyncHttpClient:
|
|
44
50
|
await self._ensure_session()
|
|
@@ -73,7 +79,7 @@ class BaseAsyncHttpClient:
|
|
|
73
79
|
default_scheme=self._default_scheme,
|
|
74
80
|
)
|
|
75
81
|
|
|
76
|
-
async def
|
|
82
|
+
async def __raise_for_status__(self, response: aiohttp.ClientResponse) -> None:
|
|
77
83
|
headers = response.headers if isinstance(
|
|
78
84
|
response.headers, Mapping) else response['headers']
|
|
79
85
|
if response.status < 400:
|
|
@@ -117,6 +123,7 @@ class BaseAsyncHttpClient:
|
|
|
117
123
|
json=json,
|
|
118
124
|
data=data,
|
|
119
125
|
timeout=request_timeout,
|
|
126
|
+
ssl=ssl_ctx,
|
|
120
127
|
**kwargs,
|
|
121
128
|
)
|
|
122
129
|
return response
|
|
@@ -145,10 +152,14 @@ class BaseAsyncHttpClient:
|
|
|
145
152
|
|
|
146
153
|
async def _ensure_session(self) -> ClientSession:
|
|
147
154
|
if self._session is None or self._session.closed:
|
|
155
|
+
if self._raise_for_status:
|
|
156
|
+
raise_for_status = self.__raise_for_status__
|
|
157
|
+
else:
|
|
158
|
+
raise_for_status = None
|
|
148
159
|
self._session = aiohttp.ClientSession(
|
|
149
160
|
timeout=self._timeout,
|
|
150
161
|
trust_env=self._trust_env,
|
|
151
|
-
raise_for_status=
|
|
162
|
+
raise_for_status=raise_for_status,
|
|
152
163
|
)
|
|
153
164
|
return self._session
|
|
154
165
|
|
|
@@ -116,7 +116,7 @@ class BaseSyncHttpClient:
|
|
|
116
116
|
except requests.RequestException as e:
|
|
117
117
|
if e.response is not None and "Content-Type" in e.response.headers and e.response.headers["Content-Type"] == "application/json":
|
|
118
118
|
data = e.response.json()
|
|
119
|
-
shared.raise_for_response(data, e.response.
|
|
119
|
+
shared.raise_for_response(data, e.response.status_code)
|
|
120
120
|
raise e
|
|
121
121
|
|
|
122
122
|
def get(self, path: str, **kwargs: Any) -> requests.Response:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{finalsa_common_http_client-0.0.6 → finalsa_common_http_client-0.0.8}/finalsa/http/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|