Skip to content

Do not add default ports for explicit hosts#687

Open
lin-hongkuan wants to merge 1 commit into
ollama:mainfrom
lin-hongkuan:fix/explicit-host-default-ports
Open

Do not add default ports for explicit hosts#687
lin-hongkuan wants to merge 1 commit into
ollama:mainfrom
lin-hongkuan:fix/explicit-host-default-ports

Conversation

@lin-hongkuan

Copy link
Copy Markdown

Summary

Stop _parse_host from appending :80 or :443 when the input already includes an explicit http:// or https:// scheme without a port.

Motivation

When callers configure a custom host such as https://example.com, the client currently normalizes it to https://example.com:443. That changes the visible configured host and can be problematic for reverse proxies or environments that expect the default port to remain implicit.

Fixes #222

Changes

  • Track whether the input included an explicit scheme.
  • Preserve the existing Ollama default port :11434 for bare hosts.
  • Avoid adding default HTTP/HTTPS ports for explicit scheme hosts without a port.
  • Add doctest examples and a parametrized regression test.

Testing

  • uv run --with pytest --with pytest-anyio --with pytest-httpserver pytest tests/test_client.py::test_parse_host_default_ports --doctest-modules ollama/_client.py8 passed in 0.64s
  • uv run --with pytest --with pytest-anyio --with pytest-httpserver pytest tests/test_client.py::test_parse_host_default_ports --doctest-modules ollama/_client.py tests/test_client.py80 passed in 3.29s
  • uv run --with ruff ruff check ollama/_client.py tests/test_client.pyAll checks passed!
  • git diff --check
  • Secret scan on diff: clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please do not append port 80 or 443 when I set a custom host, as this can lead to errors on certain gateways.

1 participant