1212
1313import asyncio
1414import json
15- from collections .abc import Collection
15+ from collections .abc import Callable , Collection
1616from typing import Any
1717
1818from .exceptions import TopicError
@@ -34,17 +34,20 @@ class _AdminHttpTransport:
3434 ``urllib.request`` call executed on a worker thread otherwise.
3535 """
3636
37- def __init__ (self , base_url : str ) -> None :
37+ def __init__ (self , base_url : str | Callable [[], str ] ) -> None :
3838 """Initialize the transport.
3939
4040 Args:
41- base_url: Base URL of the Streamline HTTP REST API .
41+ base_url: Base URL or a callable that resolves the current URL .
4242 """
4343 self ._base_url = base_url
4444
45+ def _current_base_url (self ) -> str :
46+ return self ._base_url () if callable (self ._base_url ) else self ._base_url
47+
4548 async def get (self , path : str ) -> Any :
4649 """Make an HTTP GET request to the Streamline REST API."""
47- url = f"{ self ._base_url } { path } "
50+ url = f"{ self ._current_base_url () } { path } "
4851
4952 if HAS_AIOHTTP :
5053 async with aiohttp .ClientSession () as session :
@@ -69,7 +72,7 @@ def _sync_get():
6972
7073 async def post (self , path : str , body : Any ) -> Any :
7174 """Make an HTTP POST request to the Streamline REST API."""
72- url = f"{ self ._base_url } { path } "
75+ url = f"{ self ._current_base_url () } { path } "
7376
7477 if HAS_AIOHTTP :
7578 async with aiohttp .ClientSession () as session :
@@ -97,7 +100,7 @@ def _sync_post():
97100
98101 async def delete (self , path : str ) -> None :
99102 """Make an HTTP DELETE request to the Streamline REST API."""
100- url = f"{ self ._base_url } { path } "
103+ url = f"{ self ._current_base_url () } { path } "
101104
102105 if HAS_AIOHTTP :
103106 async with aiohttp .ClientSession () as session :
0 commit comments