Skip to content

fix(llm): strip URL path in parse_host_port for Ollama base_url with /v1 suffix#1837

Merged
bug-ops merged 2 commits intomainfrom
1832-parse-host-port-path
Mar 15, 2026
Merged

fix(llm): strip URL path in parse_host_port for Ollama base_url with /v1 suffix#1837
bug-ops merged 2 commits intomainfrom
1832-parse-host-port-path

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 15, 2026

Fixes #1832.

Problem

parse_host_port() used rfind(':') to split host and port. When base_url contains a path component (e.g. http://localhost:11434/v1), port_str becomes "11434/v1" which cannot parse as u16. The fallback then returns the full URL string as the host, causing API URLs like http://localhost:11434/v1api/embed → HTTP 404.

Fix

Replace the rfind-based heuristic with url::Url::parse(), which correctly extracts scheme, host, and port while discarding path/query/fragment. A fallback rfind(':') path is retained for bare "host:port" strings without a scheme (guarded behind a scheme-presence check).

IPv6 addresses are handled via url::Host::Ipv6 match to preserve brackets in the reconstructed URL.

Tests

8 unit tests added to parse_host_port:

  • plain host
  • host + port
  • host + port + path
  • https with path
  • trailing slash
  • IPv6 with port and path
  • IPv6 without port
  • bare host:port fallback

Checklist

  • cargo +nightly fmt --check passes
  • cargo clippy --workspace --features full -- -D warnings passes
  • cargo nextest run --workspace --features full --lib --bins passes (5801 tests)
  • CHANGELOG.md updated

…/v1 suffix

Resolves #1832. parse_host_port() now uses url::Url::parse() to extract
host and port, discarding any path/query/fragment. A fallback rfind(':')
path is retained for bare "host:port" strings without a scheme.

Adds 8 unit tests covering: plain host, host+port, path suffix, https,
trailing slash, IPv6 with port, IPv6 without port, bare host:port.
@github-actions github-actions bot added documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes dependencies Dependency updates bug Something isn't working size/M Medium PR (51-200 lines) labels Mar 15, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 15, 2026 16:02
@bug-ops bug-ops merged commit b9a89bb into main Mar 15, 2026
15 checks passed
@bug-ops bug-ops deleted the 1832-parse-host-port-path branch March 15, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Dependency updates documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(llm): parse_host_port ignores URL path — Ollama base_url with /v1 suffix produces 404 on embed

1 participant