File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,4 +49,6 @@ def __init__(
4949
5050 def _build_url (self , path : str ) -> str :
5151 normalized_path = path if path .startswith ("/" ) else f"/{ path } "
52+ if normalized_path == "/api" or normalized_path .startswith ("/api/" ):
53+ return f"{ self .config .base_url } { normalized_path } "
5254 return f"{ self .config .base_url } /api{ normalized_path } "
Original file line number Diff line number Diff line change @@ -20,6 +20,15 @@ def __post_init__(self) -> None:
2020 raise HyperbrowserError ("base_url must be a string" )
2121 self .api_key = self .api_key .strip ()
2222 self .base_url = self .base_url .strip ().rstrip ("/" )
23+ if not self .base_url :
24+ raise HyperbrowserError ("base_url must not be empty" )
25+ if not (
26+ self .base_url .startswith ("https://" )
27+ or self .base_url .startswith ("http://" )
28+ ):
29+ raise HyperbrowserError (
30+ "base_url must start with 'https://' or 'http://'"
31+ )
2332
2433 @classmethod
2534 def from_env (cls ) -> "ClientConfig" :
Original file line number Diff line number Diff line change @@ -41,3 +41,11 @@ def test_client_config_rejects_non_string_values():
4141
4242 with pytest .raises (HyperbrowserError , match = "base_url must be a string" ):
4343 ClientConfig (api_key = "test-key" , base_url = None ) # type: ignore[arg-type]
44+
45+
46+ def test_client_config_rejects_empty_or_invalid_base_url ():
47+ with pytest .raises (HyperbrowserError , match = "base_url must not be empty" ):
48+ ClientConfig (api_key = "test-key" , base_url = " " )
49+
50+ with pytest .raises (HyperbrowserError , match = "base_url must start with" ):
51+ ClientConfig (api_key = "test-key" , base_url = "api.hyperbrowser.ai" )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ def test_client_build_url_normalizes_leading_slash():
77 try :
88 assert client ._build_url ("/session" ) == "https://api.hyperbrowser.ai/api/session"
99 assert client ._build_url ("session" ) == "https://api.hyperbrowser.ai/api/session"
10+ assert client ._build_url ("/api/session" ) == "https://api.hyperbrowser.ai/api/session"
1011 finally :
1112 client .close ()
1213
You can’t perform that action at this time.
0 commit comments