If the request is secured using DTLS, let |url| be the string
"coaps://". Otherwise, let |url| be the string "coap://".
If the request includes a Uri-Host Option, let |host| be that
option's value, where any non-ASCII characters are replaced by
their corresponding percent-encoding. If |host| is not a valid
reg-name or IP-literal or IPv4address, fail the algorithm. If
the request does not include a Uri-Host Option, let |host| be
the IP-literal (making use of the conventions of [RFC5952]) or
IPv4address representing the request's destination IP address.
Append |host| to |url|.
If the request includes a Uri-Port Option, let |port| be that
option's value. Otherwise, let |port| be the request's
destination UDP port.
If |port| is not the default port for the scheme, then append a
single U+003A COLON character (:) followed by the decimal
representation of |port| to |url|.
Let |resource name| be the empty string. For each Uri-Path
Option in the request, append a single character U+002F SOLIDUS
(/) followed by the option's value to |resource name|, after
converting any character that is not either in the "unreserved"
set, in the "sub-delims" set, a U+003A COLON (:) character, or a
U+0040 COMMERCIAL AT (@) character to its percent-encoded form.
If |resource name| is the empty string, set it to a single
character U+002F SOLIDUS (/).
For each Uri-Query Option in the request, append a single
character U+003F QUESTION MARK (?) (first option) or U+0026
AMPERSAND (&) (subsequent options) followed by the option's
value to |resource name|, after converting any character that is
not either in the "unreserved" set, in the "sub-delims" set
(except U+0026 AMPERSAND (&)), a U+003A COLON (:), a U+0040
COMMERCIAL AT (@), a U+002F SOLIDUS (/), or a U+003F QUESTION
MARK (?) character to its percent-encoded form.