canopus icon indicating copy to clipboard operation
canopus copied to clipboard

Decomposing URIs into Options

Open zubairhamed opened this issue 9 years ago • 0 comments

The steps to parse a request's options from a string |url| are as follows. These steps either result in zero or more of the Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options being included in the request or they fail.

  1. If the |url| string is not an absolute URI ([RFC3986]), then fail this algorithm.

  2. Resolve the |url| string using the process of reference resolution defined by [RFC3986]. At this stage, the URL is in ASCII encoding [RFC0020], even though the decoded components will be interpreted in UTF-8 [RFC3629] after steps 5, 8, and 9.

    NOTE: It doesn't matter what it is resolved relative to, since we already know it is an absolute URL at this point.

  3. If |url| does not have a component whose value, when converted to ASCII lowercase, is "coap" or "coaps", then fail this algorithm.

  4. If |url| has a component, then fail this algorithm.

  5. If the component of |url| does not represent the request's destination IP address as an IP-literal or IPv4address, include a Uri-Host Option and let that option's value be the value of the component of |url|, converted to ASCII lowercase, and then convert all percent-encodings ("%" followed by two hexadecimal digits) to the corresponding characters.

  NOTE: In the usual case where the request's destination IP
  address is derived from the host part, this ensures that a Uri-
  Host Option is only used for a <host> component of the form reg-
  name.
  1. If |url| has a component, then let |port| be that component's value interpreted as a decimal integer; otherwise, let |port| be the default port for the scheme.

  2. If |port| does not equal the request's destination UDP port, include a Uri-Port Option and let that option's value be |port|.

  3. If the value of the component of |url| is empty or consists of a single slash character (U+002F SOLIDUS "/"), then move to the next step.

    Otherwise, for each segment in the component, include a Uri-Path Option and let that option's value be the segment (not including the delimiting slash characters) after converting each percent-encoding ("%" followed by two hexadecimal digits) to the corresponding byte.

  4. If |url| has a component, then, for each argument in the component, include a Uri-Query Option and let that option's value be the argument (not including the question mark and the delimiting ampersand characters) after converting each percent-encoding to the corresponding byte.

Note that these rules completely resolve any percent-encoding.

zubairhamed avatar Mar 06 '15 14:03 zubairhamed