Skip to content

Commit 88a5deb

Browse files
authored
fix: migrate HTTP client usage to httpx2 (#948)
1 parent ebce8ad commit 88a5deb

16 files changed

Lines changed: 19251 additions & 19253 deletions

File tree

diracx-api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ classifiers = [
1515
dependencies = [
1616
"diracx-client",
1717
"diracx-core",
18-
"httpx",
18+
"httpx2",
1919
"zstandard",
2020
]
2121
dynamic = ["version"]

diracx-api/src/diracx/api/jobs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pathlib import Path
1212
from typing import BinaryIO, Literal
1313

14-
import httpx
14+
import httpx2
1515
import zstandard
1616

1717
from diracx.client.aio import AsyncDiracClient
@@ -88,7 +88,7 @@ async def create_sandbox(paths: list[Path], *, client: AsyncDiracClient) -> str:
8888
if res.url:
8989
logger.debug("Uploading sandbox for %s", res.pfn)
9090
files = {"file": ("file", tar_fh)}
91-
async with httpx.AsyncClient() as httpx_client:
91+
async with httpx2.AsyncClient() as httpx_client:
9292
response = await httpx_client.post(
9393
res.url, data=res.fields, files=files
9494
)
@@ -111,7 +111,7 @@ async def download_sandbox(pfn: str, destination: Path, *, client: AsyncDiracCli
111111
res = await client.jobs.get_sandbox_file(pfn=pfn)
112112
logger.debug("Downloading sandbox for %s", pfn)
113113
with tempfile.TemporaryFile(mode="w+b") as fh:
114-
async with httpx.AsyncClient() as http_client:
114+
async with httpx2.AsyncClient() as http_client:
115115
response = await http_client.get(res.url)
116116
# TODO: Handle this error better
117117
response.raise_for_status()

diracx-cli/src/diracx/cli/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import typer
99
from azure.core.exceptions import ClientAuthenticationError
10-
from httpx import ConnectError
10+
from httpx2 import ConnectError
1111
from rich import print
1212

1313

diracx-client/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ classifiers = [
1212
"Topic :: Scientific/Engineering",
1313
"Topic :: System :: Distributed Computing",
1414
]
15-
dependencies = ["azure-core", "diracx-core", "isodate", "httpx", "pyjwt"]
15+
dependencies = ["azure-core", "diracx-core", "isodate", "httpx2", "pyjwt"]
1616
dynamic = ["version"]
1717

1818
[project.optional-dependencies]

diracx-client/src/diracx/client/patches/client/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from typing import TextIO
1717
from urllib import parse
1818

19-
import httpx
19+
import httpx2
2020
import jwt
2121
from azure.core.credentials import AccessToken
2222
from diracx.core.utils import EXPIRES_GRACE_SECONDS, serialize_credentials
@@ -40,7 +40,7 @@ def get_openid_configuration(
4040
endpoint: str, *, verify: bool | str = True
4141
) -> dict[str, str]:
4242
"""Get the openid configuration from the .well-known endpoint"""
43-
response = httpx.get(
43+
response = httpx2.get(
4444
url=parse.urljoin(endpoint, ".well-known/openid-configuration"),
4545
verify=verify,
4646
)
@@ -120,7 +120,7 @@ def refresh_token(
120120
verify: bool | str = True,
121121
) -> TokenResponse:
122122
"""Refresh the access token using the refresh_token flow."""
123-
response = httpx.post(
123+
response = httpx2.post(
124124
url=token_endpoint,
125125
data={
126126
"client_id": client_id,

diracx-client/src/diracx/client/patches/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
import os
99
from diracx.core.utils import EXPIRES_GRACE_SECONDS, serialize_credentials
10-
import httpx
10+
import httpx2
1111
import jwt
1212

1313
from datetime import datetime, timezone
@@ -43,7 +43,7 @@ def get_openid_configuration(
4343
endpoint: str, *, verify: bool | str = True
4444
) -> Dict[str, str]:
4545
"""Get the openid configuration from the .well-known endpoint"""
46-
response = httpx.get(
46+
response = httpx2.get(
4747
url=parse.urljoin(endpoint, ".well-known/openid-configuration"),
4848
verify=verify,
4949
)
@@ -123,7 +123,7 @@ def refresh_token(
123123
verify: bool | str = True,
124124
) -> TokenResponse:
125125
"""Refresh the access token using the refresh_token flow."""
126-
response = httpx.post(
126+
response = httpx2.post(
127127
url=token_endpoint,
128128
data={
129129
"client_id": client_id,

diracx-core/tests/test_s3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import random
66
import secrets
77

8-
import httpx
8+
import httpx2
99
import pytest
1010
from aiobotocore.session import get_session
1111

@@ -82,7 +82,7 @@ async def test_presigned_upload_moto(moto_s3):
8282
)
8383

8484
# Upload the file
85-
async with httpx.AsyncClient() as client:
85+
async with httpx2.AsyncClient() as client:
8686
r = await client.post(
8787
upload_info["url"],
8888
data=upload_info["fields"],
@@ -153,7 +153,7 @@ async def test_presigned_upload_minio(
153153
minio_client, test_bucket, key, "sha256", checksum, size, 60
154154
)
155155
# Ensure the URL doesn't work
156-
async with httpx.AsyncClient() as client:
156+
async with httpx2.AsyncClient() as client:
157157
r = await client.post(
158158
upload_info["url"], data=upload_info["fields"], files={"file": content}
159159
)

diracx-logic/src/diracx/logic/auth/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
import secrets
77

8-
import httpx
8+
import httpx2
99
from cachetools import TTLCache
1010
from cryptography.fernet import Fernet
1111
from joserfc import jwt
@@ -34,7 +34,7 @@ async def get_server_metadata(url: str):
3434
"""Get the server metadata from the IAM."""
3535
server_metadata = _server_metadata_cache.get(url)
3636
if server_metadata is None:
37-
async with httpx.AsyncClient() as c:
37+
async with httpx2.AsyncClient() as c:
3838
res = await c.get(url)
3939
if res.status_code != 200:
4040
raise IAMServerError("Failed to retrieve IAM server metadata")
@@ -68,7 +68,7 @@ async def fetch_jwk_set(url: str):
6868
if not jwks_uri:
6969
raise RuntimeError('Missing "jwks_uri" in metadata')
7070

71-
async with httpx.AsyncClient() as c:
71+
async with httpx2.AsyncClient() as c:
7272
res = await c.get(jwks_uri)
7373
if res.status_code != 200:
7474
# TODO: Better error handling
@@ -166,7 +166,7 @@ async def get_token_from_iam(
166166
"redirect_uri": redirect_uri,
167167
}
168168

169-
async with httpx.AsyncClient() as c:
169+
async with httpx2.AsyncClient() as c:
170170
res = await c.post(
171171
token_endpoint,
172172
data=data,

diracx-logic/tests/jobs/test_sandboxes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import botocore.exceptions
1010
import freezegun
11-
import httpx
11+
import httpx2
1212
import pytest
1313
import sqlalchemy
1414

@@ -92,7 +92,7 @@ async def test_upload_and_clean(
9292

9393
# Do the actual upload
9494
files = {"file": ("file", BytesIO(data))}
95-
async with httpx.AsyncClient() as httpx_client:
95+
async with httpx2.AsyncClient() as httpx_client:
9696
response = await httpx_client.post(
9797
response.url, data=response.fields, files=files
9898
)
@@ -111,7 +111,7 @@ async def test_upload_and_clean(
111111
download_response = await get_sandbox_file(
112112
expected_pfn, sandbox_metadata_db, sandbox_settings
113113
)
114-
async with httpx.AsyncClient() as httpx_client:
114+
async with httpx2.AsyncClient() as httpx_client:
115115
response = await httpx_client.get(download_response.url)
116116
response.raise_for_status()
117117
assert response.content == data
@@ -124,7 +124,7 @@ async def test_upload_and_clean(
124124
download_response = await get_sandbox_file(
125125
expected_pfn, sandbox_metadata_db, sandbox_settings
126126
)
127-
async with httpx.AsyncClient() as httpx_client:
127+
async with httpx2.AsyncClient() as httpx_client:
128128
response = await httpx_client.get(download_response.url)
129129
response.raise_for_status()
130130
assert response.content == data

diracx-routers/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies = [
2121
"python-dotenv", # TODO: We might not need this
2222
"python-multipart",
2323
"fastapi>=0.121.0",
24-
"httpx",
24+
"httpx2",
2525
"joserfc",
2626
"pydantic >=2.10",
2727
"uvicorn",
@@ -34,7 +34,7 @@ dependencies = [
3434
dynamic = ["version"]
3535

3636
[project.optional-dependencies]
37-
testing = ["diracx-testing", "moto[server]", "pytest-httpx", "freezegun", "pyjwt"]
37+
testing = ["diracx-testing", "moto[server]", "httpx2-pytest", "freezegun", "pyjwt"]
3838
types = [
3939
"types-cachetools",
4040
"types-python-dateutil",

0 commit comments

Comments
 (0)