Add URL path to client URL in in Client._parse_host() (#170)

* Add URL path to client URL in in Client._parse_host()

* add tests for url path

* improve URL path handling

* restore trailing space

* remove extraneous path assignment

* Fix url path test

Co-authored-by: Michael Yang <mxyng@pm.me>

---------

Co-authored-by: Ben Plunkert <ben@plunkert.com>
Co-authored-by: Michael Yang <mxyng@pm.me>
This commit is contained in:
Ben Plunkert 2024-08-23 16:09:45 -04:00 committed by GitHub
parent 8b694bb0f4
commit dfdeb7cef3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -987,6 +987,14 @@ def _parse_host(host: Optional[str]) -> str:
'http://example.com:11434'
>>> _parse_host('example.com:56789/')
'http://example.com:56789'
>>> _parse_host('example.com/path')
'http://example.com:11434/path'
>>> _parse_host('example.com:56789/path')
'http://example.com:56789/path'
>>> _parse_host('https://example.com:56789/path')
'https://example.com:56789/path'
>>> _parse_host('example.com:56789/path/')
'http://example.com:56789/path'
"""
host, port = host or '', 11434
@ -1002,4 +1010,7 @@ def _parse_host(host: Optional[str]) -> str:
host = split.hostname or '127.0.0.1'
port = split.port or port
if path := split.path.strip('/'):
return f'{scheme}://{host}:{port}/{path}'
return f'{scheme}://{host}:{port}'