Skip to content

Commit 9721c53

Browse files
committed
Turn off follow_redirects for httpx clients and only enable it for a specific endpoints... this may make httpx happier.
1 parent 3c7be64 commit 9721c53

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/sumo/wrapper/sumo_client.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import asyncio
33
import httpx
44
import jwt
5+
import re
56

67
from ._blob_client import BlobClient
78
from ._logging import LogHandlerSumo
@@ -49,8 +50,8 @@ def __init__(
4950
raise ValueError(f"Invalid environment: {env}")
5051

5152
self._retry_strategy = retry_strategy
52-
self._client = httpx.Client(follow_redirects=True)
53-
self._async_client = httpx.AsyncClient(follow_redirects=True)
53+
self._client = httpx.Client()
54+
self._async_client = httpx.AsyncClient()
5455

5556
self._timeout = timeout
5657

@@ -197,12 +198,17 @@ def get(self, path: str, params: dict = None) -> dict:
197198

198199
headers.update(self.auth.get_authorization())
199200

201+
follow_redirects = False
202+
if re.match(r"^/objects\('[0-9a-fA-F-]{8}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{12}'\)/blob$",
203+
path) is not None:
204+
follow_redirects = True
205+
200206
def _get():
201207
return self._client.get(
202208
f"{self.base_url}{path}",
203209
params=params,
204210
headers=headers,
205-
follow_redirects=True,
211+
follow_redirects=follow_redirects,
206212
timeout=self._timeout,
207213
)
208214

@@ -424,11 +430,17 @@ async def get_async(self, path: str, params: dict = None):
424430

425431
headers.update(self.auth.get_authorization())
426432

433+
follow_redirects = False
434+
if re.match(r"^/objects\('[0-9a-fA-F-]{8}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{12}'\)/blob$",
435+
path) is not None:
436+
follow_redirects = True
437+
427438
async def _get():
428439
return await self._async_client.get(
429440
f"{self.base_url}{path}",
430441
params=params,
431442
headers=headers,
443+
follow_redirects = follow_redirects,
432444
timeout=self._timeout,
433445
)
434446

0 commit comments

Comments
 (0)