zubairhamed / canopus

CoAP Client/Server implementing RFC 7252 for the Go Language
Apache License 2.0
154 stars 41 forks source link

Decomposing URIs into Options #35

Open zubairhamed opened 9 years ago

zubairhamed commented 9 years ago

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.

    1. 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 component of the form reg- name.
  5. 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.
  6. If |port| does not equal the request's destination UDP port, include a Uri-Port Option and let that option's value be |port|.
  7. 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.

  8. 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.