Add public Origin API

Merged
KL
3mo ago
+203-21

Summary

  • add a public, immutable, and hashable Origin value object
  • expose normalized origins through URL.origin
  • support effective ports for FTP, HTTP(S), and WS(S), including canonical IPv6 comparison
  • use the shared value object for existing origin comparisons
  • document and test the public API

Motivation

Applications and integrations sometimes need a reusable representation of a URL's scheme, host, and effective port. Origin provides that representation without including user information, paths, queries, or fragments.

Testing

  • pytest: 1,967 passed, 1 skipped
  • ruff format --check --diff
  • ruff check
  • mypy src/httpx2 tests/httpx2 src/httpcore2 tests/httpcore2
  • python scripts/unasync.py --check