finalsa-common-http-client 0.0.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: finalsa-common-http-client
3
- Version: 0.0.7
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
@@ -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 raise_for_status(self, response: aiohttp.ClientResponse) -> None:
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=self.raise_for_status,
162
+ raise_for_status=raise_for_status,
152
163
  )
153
164
  return self._session
154
165
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "finalsa-common-http-client"
3
- version = "0.0.7"
3
+ version = "0.0.8"
4
4
  description = "HTTP client library for common data types used in business applications"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"