File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ def __init__(
6464 raise HyperbrowserError ("API key must be provided" )
6565
6666 self .config = config
67+ parsed_base_url = urlparse (self .config .base_url )
68+ self ._base_url_has_api_suffix = parsed_base_url .path .rstrip ("/" ).endswith (
69+ "/api"
70+ )
6771 self .transport = transport (config .api_key , headers = config .headers )
6872
6973 def _build_url (self , path : str ) -> str :
@@ -78,16 +82,13 @@ def _build_url(self, path: str) -> str:
7882 if parsed_path .scheme :
7983 raise HyperbrowserError ("path must be a relative API path" )
8084 normalized_path = f"/{ stripped_path .lstrip ('/' )} "
81- parsed_base_url = urlparse (self .config .base_url )
82- base_path = parsed_base_url .path .rstrip ("/" )
83- base_has_api_suffix = base_path .endswith ("/api" )
8485
8586 if normalized_path == "/api" or normalized_path .startswith ("/api/" ):
86- if base_has_api_suffix :
87+ if self . _base_url_has_api_suffix :
8788 deduped_path = normalized_path [len ("/api" ) :]
8889 return f"{ self .config .base_url } { deduped_path } "
8990 return f"{ self .config .base_url } { normalized_path } "
9091
91- if base_has_api_suffix :
92+ if self . _base_url_has_api_suffix :
9293 return f"{ self .config .base_url } { normalized_path } "
9394 return f"{ self .config .base_url } /api{ normalized_path } "
You can’t perform that action at this time.
0 commit comments