Skip to content

Commit 303d6cd

Browse files
authored
Merge pull request #37 from comfyorg/main
2 parents 6e7cd33 + 4c0dd11 commit 303d6cd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/comfy_script/client/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@ def __init__(
3535
3636
e.g. `lambda: aiohttp.ClientSession(auth=aiohttp.BasicAuth('Aladdin', 'open sesame'))`
3737
'''
38+
self.base_url = self._normalize_base_url(base_url)
39+
40+
# Do not pass base_url to ClientSession, as it only supports absolute URLs without path part
41+
self._session_factory = session_factory
42+
43+
def _normalize_base_url(self, base_url: str | URL):
3844
if base_url is None:
3945
base_url = 'http://127.0.0.1:8188/'
40-
elif not isinstance(base_url, str):
46+
if not isinstance(base_url, str):
4147
base_url = str(base_url)
42-
43-
if not base_url.startswith('http://'):
48+
if not base_url.startswith(('http://', 'https://')):
4449
base_url = 'http://' + base_url
4550
if not base_url.endswith('/'):
4651
base_url += '/'
47-
self.base_url = base_url
48-
49-
# Do not pass base_url to ClientSession, as it only supports absolute URLs without path part
50-
self._session_factory = session_factory
52+
return base_url
5153

5254
def session(self) -> aiohttp.ClientSession:
5355
'''Because `aiohttp.ClientSession` is not event-loop-safe (thread-safe), a new session should be created for each request to avoid potential issues. Also, `aiohttp.ClientSession` cannot be closed in a sync manner.'''

0 commit comments

Comments
 (0)