Skip to content

Commit

Permalink
fix: merged default headers instead of replace
Browse files Browse the repository at this point in the history
Also add argument for replace or not default headers
  • Loading branch information
leynier committed Dec 11, 2021
1 parent 7629707 commit 96d390c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions gotrue/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def __init__(
self,
*,
url: str = GOTRUE_URL,
headers: Dict[str, str] = DEFAULT_HEADERS,
headers: Dict[str, str] = {},
auto_refresh_token: bool = True,
persist_session: bool = True,
local_storage: AsyncSupportedStorage = AsyncMemoryStorage(),
cookie_options: CookieOptions = CookieOptions.parse_obj(COOKIE_OPTIONS),
api: Optional[AsyncGoTrueAPI] = None,
replace_default_headers: bool = False,
) -> None:
"""Create a new client
Expand Down Expand Up @@ -64,7 +65,12 @@ def __init__(
self.auto_refresh_token = auto_refresh_token
self.persist_session = persist_session
self.local_storage = local_storage
args = {"url": url, "headers": headers, "cookie_options": cookie_options}
empty_or_default_headers = {} if replace_default_headers else DEFAULT_HEADERS
args = {
"url": url,
"headers": {**empty_or_default_headers, **headers},
"cookie_options": cookie_options,
}
self.api = api if api else AsyncGoTrueAPI(**args)

async def __aenter__(self) -> AsyncGoTrueClient:
Expand Down
10 changes: 8 additions & 2 deletions gotrue/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def __init__(
self,
*,
url: str = GOTRUE_URL,
headers: Dict[str, str] = DEFAULT_HEADERS,
headers: Dict[str, str] = {},
auto_refresh_token: bool = True,
persist_session: bool = True,
local_storage: SyncSupportedStorage = SyncMemoryStorage(),
cookie_options: CookieOptions = CookieOptions.parse_obj(COOKIE_OPTIONS),
api: Optional[SyncGoTrueAPI] = None,
replace_default_headers: bool = False,
) -> None:
"""Create a new client
Expand Down Expand Up @@ -64,7 +65,12 @@ def __init__(
self.auto_refresh_token = auto_refresh_token
self.persist_session = persist_session
self.local_storage = local_storage
args = {"url": url, "headers": headers, "cookie_options": cookie_options}
empty_or_default_headers = {} if replace_default_headers else DEFAULT_HEADERS
args = {
"url": url,
"headers": {**empty_or_default_headers, **headers},
"cookie_options": cookie_options,
}
self.api = api if api else SyncGoTrueAPI(**args)

def __enter__(self) -> SyncGoTrueClient:
Expand Down

0 comments on commit 96d390c

Please sign in to comment.