Skip to content

fix(config): enclose IPv6 node hosts in brackets when building the URL - #155

Open
RaphaelFakhri wants to merge 3 commits into
typesense:masterfrom
RaphaelFakhri:fix/ipv6-node-url
Open

RaphaelFakhri wants to merge 3 commits into
typesense:masterfrom
RaphaelFakhri:fix/ipv6-node-url

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Change summary

Node.url() builds the node URL as {protocol}://{host}:{port}{path}. When the host is an IPv6 literal, the result (for example, http://::1:8108) is not a valid URL, and every request fails with httpx.InvalidURL: Invalid port.

This affects both node formats:

  • URL strings such as "http://[::1]:8108", because Node.from_url stores urlparse(url).hostname, which drops the brackets.
  • Node dicts such as {"host": "::1", "port": 8108, "protocol": "http"}.

Node.url() now encloses a host that contains : in brackets, unless the host is already bracketed. IPv4 and hostname nodes produce the same URL as before.

Tests added in tests/node_test.py:

  • test_node_url_ipv6_host
  • test_node_url_bracketed_ipv6_host
  • test_node_from_url_ipv6

The first and third fail on master and pass with this change.

PR checklist

  • Tests added for the change.
  • ruff check and mypy src/typesense pass.

Fixes #154

This branch has not been deployed

No deployments
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.

IPv6 node addresses produce an invalid request URL

2 participants