urlcanon

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package urlcanon implements AdCP URL-identifier canonicalization, the single normalization an AdCP implementation applies before comparing two URLs for identity (e.g. matching a seller_agent_url to its registered active package set, or computing the RFC 9421 @target-uri signature component).

The algorithm is defined in the AdCP reference documentation at docs/reference/url-canonicalization. It is intentionally distinct from tmproto.CanonicalizeURL, which produces the url_hash content-dedup form (lowercased, query-sorted, fragment-stripped) used for artifact hashing — do not substitute one for the other.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BracketIfIPv6

func BracketIfIPv6(host string) string

BracketIfIPv6 wraps host in brackets when it parses as an IPv6 address literal. net.SplitHostPort strips the brackets; canonical authority keeps them.

func Canonicalize

func Canonicalize(rawURL string) (string, error)

Canonicalize applies the AdCP URL-identifier canonicalization (docs/reference/url-canonicalization):

  1. Lowercase scheme.
  2. Lowercase host; IDN → Punycode (url.Parse handles Punycode already).
  3. Strip userinfo.
  4. Strip default ports (:443 for https, :80 for http).
  5. remove_dot_segments on path; empty path with authority becomes "/".
  6. Normalize percent-encoding: decode unreserved octets, uppercase the hex of reserved ones.
  7. Preserve query byte-for-byte.
  8. Strip fragment.

rawURL is the URL as received on the wire. For outgoing signed requests the signer supplies the URL string it will send; for incoming, the verifier reconstructs it from scheme + Host + RequestURI.

func IsDefaultPort

func IsDefaultPort(scheme, port string) bool

IsDefaultPort reports whether port is the default for scheme (443 for https, 80 for http) and may therefore be stripped from a canonical authority.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL