masque_uri_ip (masque v0.7.0)

View Source

URI 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

ip_ipproto/0

-type ip_ipproto() :: '*' | 0..255.

ip_target/0

-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)

parse_error/0

-type parse_error() ::
          absolute_uri_required | bad_template | bad_target | bad_ipproto | no_match | missing_variables.

Functions

expand(Template, _)

-spec expand(masque_uri_template:template(), #{target := ip_target(), ipproto := ip_ipproto()}) ->
                binary().

format_ipproto(N)

-spec format_ipproto(ip_ipproto()) -> binary().

format_target(IP)

-spec format_target(ip_target()) -> binary().

Render a typed target back to its wire-form binary.

match(Template, Path)

-spec match(masque_uri_template:template(), binary()) ->
               {ok, #{target := ip_target(), ipproto := ip_ipproto()}} | {error, parse_error()}.

parse_client_template(Bin)

-spec parse_client_template(binary()) -> {ok, masque_uri_template:template()} | {error, parse_error()}.

parse_ipproto(Bin)

-spec parse_ipproto(binary()) -> {ok, ip_ipproto()} | {error, bad_ipproto}.

parse_server_template(Bin)

-spec parse_server_template(binary()) -> {ok, masque_uri_template:template()} | {error, parse_error()}.

parse_target(Bin)

-spec parse_target(binary()) -> {ok, ip_target()} | {error, bad_target}.

Parse a wire-form binary target into the typed form.

validate_ipproto(N)

-spec validate_ipproto(ip_ipproto()) -> boolean().

validate_target(T)

-spec validate_target(ip_target()) -> boolean().

Validate an already-typed target. Returns boolean.