Skip to content

Commit

Permalink
Turn off follow_redirects for httpx clients and only enable it for a …
Browse files Browse the repository at this point in the history
…specific endpoints... this may make httpx happier.
  • Loading branch information
rwiker committed Nov 14, 2024
1 parent 3c7be64 commit 9721c53
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/sumo/wrapper/sumo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import httpx
import jwt
import re

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

self._retry_strategy = retry_strategy
self._client = httpx.Client(follow_redirects=True)
self._async_client = httpx.AsyncClient(follow_redirects=True)
self._client = httpx.Client()
self._async_client = httpx.AsyncClient()

self._timeout = timeout

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

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

follow_redirects = False
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$",
path) is not None:
follow_redirects = True

def _get():
return self._client.get(
f"{self.base_url}{path}",
params=params,
headers=headers,
follow_redirects=True,
follow_redirects=follow_redirects,
timeout=self._timeout,
)

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

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

follow_redirects = False
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$",
path) is not None:
follow_redirects = True

async def _get():
return await self._async_client.get(
f"{self.base_url}{path}",
params=params,
headers=headers,
follow_redirects = follow_redirects,
timeout=self._timeout,
)

Expand Down

0 comments on commit 9721c53

Please sign in to comment.