Skip to content

Commit 05487a9

Browse files
committed
fix: build-sync in storage
1 parent cbf71bb commit 05487a9

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/storage/src/storage3/_sync/bucket.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
from typing import Any, Optional
44

5-
from httpx import Client, HTTPStatusError, Response
6-
from httpx._types import HeaderTypes
5+
from httpx import Client, Headers, HTTPStatusError, Response
76
from yarl import URL
87

98
from ..exceptions import StorageApiError
@@ -16,7 +15,7 @@
1615
class SyncStorageBucketAPI:
1716
"""This class abstracts access to the endpoint to the Get, List, Empty, and Delete operations on a bucket"""
1817

19-
def __init__(self, session: Client, url: str, headers: HeaderTypes) -> None:
18+
def __init__(self, session: Client, url: str, headers: Headers) -> None:
2019
if url and url[-1] != "/":
2120
print("Storage endpoint URL should have a trailing slash.")
2221
url += "/"

src/storage/src/storage3/_sync/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Optional
44
from warnings import warn
55

6-
from httpx import Client
6+
from httpx import Client, Headers
77

88
from storage3.constants import DEFAULT_TIMEOUT
99

@@ -63,7 +63,7 @@ def __init__(
6363
follow_redirects=True,
6464
http2=True,
6565
)
66-
super().__init__(self.session, url, headers)
66+
super().__init__(self.session, url, Headers(headers))
6767

6868
def __enter__(self) -> SyncStorageClient:
6969
return self
@@ -79,4 +79,4 @@ def from_(self, id: str) -> SyncBucketProxy:
7979
id
8080
The unique identifier of the bucket
8181
"""
82-
return SyncBucketProxy(id, self._base_url, self._client)
82+
return SyncBucketProxy(id, self._base_url, self._headers, self._client)

src/storage/src/storage3/_sync/file_api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pathlib import Path
99
from typing import Any, List, Literal, Optional, Union, cast
1010

11-
from httpx import Client, HTTPStatusError, Response
11+
from httpx import Client, Headers, HTTPStatusError, Response
1212
from yarl import URL
1313

1414
from ..constants import DEFAULT_FILE_OPTIONS, DEFAULT_SEARCH_OPTIONS
@@ -49,6 +49,7 @@ class SyncBucketActionsMixin:
4949
id: str
5050
_base_url: URL
5151
_client: Client
52+
_headers: Headers
5253

5354
def _request(
5455
self,
@@ -62,10 +63,12 @@ def _request(
6263
) -> Response:
6364
try:
6465
url_path = self._base_url.joinpath(*path).with_query(query_params)
66+
headers = headers or dict()
67+
headers.update(self._headers)
6568
response = self._client.request(
6669
method,
6770
str(url_path),
68-
headers=headers or {},
71+
headers=headers,
6972
json=json,
7073
files=files,
7174
**kwargs,
@@ -561,4 +564,5 @@ class SyncBucketProxy(SyncBucketActionsMixin):
561564

562565
id: str
563566
_base_url: URL
567+
_headers: Headers
564568
_client: Client = field(repr=False)

src/storage/tests/_sync/test_bucket.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from unittest.mock import Mock
22

33
import pytest
4-
from httpx import Client, HTTPStatusError, Response
4+
from httpx import Client, Headers, HTTPStatusError, Response
55

66
from storage3 import SyncBucket, SyncStorageBucketAPI
77
from storage3.exceptions import StorageApiError
@@ -16,12 +16,12 @@ def mock_client():
1616

1717

1818
@pytest.fixture
19-
def headers() -> dict[str, str]:
20-
return {}
19+
def headers() -> Headers:
20+
return Headers()
2121

2222

2323
@pytest.fixture
24-
def storage_api(mock_client: Client, headers: dict[str, str]) -> SyncStorageBucketAPI:
24+
def storage_api(mock_client: Client, headers: Headers) -> SyncStorageBucketAPI:
2525
return SyncStorageBucketAPI(mock_client, "", headers)
2626

2727

0 commit comments

Comments
 (0)