Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn off follow_redirects for httpx clients... #215

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 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,22 @@ 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$", # noqa: E501
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 +435,22 @@ 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$", # noqa: E501
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
Loading