masque_uri_ip (masque v0.7.0)
View SourceURI template handling for RFC 9484 CONNECT-IP.
RFC 9484 section 3 defines the request path as the expansion of a URI Template with two variables, target and ipproto.
Target values: the wildcard <<"*">>, an IPv4 literal (<<"192.0.2.1">>), an IPv6 literal (colons percent-encoded on the wire), a DNS reg-name per RFC 3986, or a prefix <<"addr/len">> (the slash appears as %2F inside the path segment and is percent-decoded by the engine).
ipproto values: the wildcard <<"*">> or a decimal integer in the range 0..255 with no leading zeros other than the digit itself.
The module distinguishes client-side and server-side template inputs. parse_client_template/1 requires an absolute URI template per RFC 9484 section 3. parse_server_template/1 accepts either a path+query match pattern or an absolute URI (whose path+query portion is used).
Summary
Functions
Render a typed target back to its wire-form binary.
Parse a wire-form binary target into the typed form.
Validate an already-typed target. Returns boolean.
Types
-type ip_ipproto() :: '*' | 0..255.
-type ip_target() :: '*' | inet:ip4_address() | inet:ip6_address() | {4, inet:ip4_address(), 0..32} | {6, inet:ip6_address(), 0..128} | binary().
DNS name (validated)
-type parse_error() ::
absolute_uri_required | bad_template | bad_target | bad_ipproto | no_match | missing_variables.
Functions
-spec expand(masque_uri_template:template(), #{target := ip_target(), ipproto := ip_ipproto()}) -> binary().
-spec format_ipproto(ip_ipproto()) -> binary().
Render a typed target back to its wire-form binary.
-spec match(masque_uri_template:template(), binary()) -> {ok, #{target := ip_target(), ipproto := ip_ipproto()}} | {error, parse_error()}.
-spec parse_client_template(binary()) -> {ok, masque_uri_template:template()} | {error, parse_error()}.
-spec parse_ipproto(binary()) -> {ok, ip_ipproto()} | {error, bad_ipproto}.
-spec parse_server_template(binary()) -> {ok, masque_uri_template:template()} | {error, parse_error()}.
Parse a wire-form binary target into the typed form.
-spec validate_ipproto(ip_ipproto()) -> boolean().
Validate an already-typed target. Returns boolean.