|
1 | 1 | # `httppath`
|
2 | 2 |
|
3 | 3 | This protocol encodes an HTTP Path to a resource. In the string representation,
|
4 |
| -characters in the reserved set are percent-encoded ( "/" becomes "%2F"). |
5 |
| -Percent-encoding itself is defined by [RFC 3986 Section |
6 |
| -2.1](https://datatracker.ietf.org/doc/html/rfc3986#section-2.1). In the binary representation, no escaping is needed as the value is length prefixed. |
7 |
| - |
8 |
| -To ease implementation and benefit from reusing existing percent-encoding logic |
9 |
| -present in many environments (Go's |
10 |
| -[url.PathEscape ](https://pkg.go.dev/net/[email protected]#PathEscape); JS's |
11 |
| -[encodeURIComponent](http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent); |
12 |
| -and Rust's [many |
13 |
| -crates](https://crates.io/search?q=percent%20encode&sort=downloads)), it is |
14 |
| -acceptable to encode more characters than the reserved set. While it's not |
15 |
| -necessary to encode a space " " as %20, it's is acceptable to do so. |
| 4 | +the path is encoded in a way consistent with a single URI Path segment per [RFC 3986 Section |
| 5 | +3.3](https://datatracker.ietf.org/doc/html/rfc3986#autoid-23). Specifically |
| 6 | +following the grammar of a single `segment-nz`. In the binary |
| 7 | +representation, no encoding is needed as the value is length prefixed. |
16 | 8 |
|
17 | 9 | When comparing multiaddrs, implementations should compare their binary
|
18 | 10 | representation to avoid ambiguities over which characters were escaped.
|
19 | 11 |
|
20 |
| -## Reserved Characters |
| 12 | +## Examples |
21 | 13 |
|
22 |
| -| Character | Reason | |
23 |
| -| --------- | ---------------------------------------------------------------------------------------------------- | |
24 |
| -| `/` | Multiaddr component separator | |
25 |
| -| `%` | Percent encoding indicator | |
26 |
| -| `?` | Marks the end of an HTTP path | |
27 |
| -| `#` | Reserved gen-delim character by [rfc3986](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2) | |
28 |
| -| `[` | Reserved gen-delim character by [rfc3986](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2) | |
29 |
| -| `]` | Reserved gen-delim character by [rfc3986](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2) | |
| 14 | +The following is a table of examples converting some common HTTP paths to their Multiaddr string form. |
| 15 | + |
| 16 | +| HTTP Path | Multiaddr string form | |
| 17 | +| --------------- | -------------------------------- | |
| 18 | +| / | n/a. This is implied. | |
| 19 | +| /user | `/httppath/user` | |
| 20 | +| /api/v0/login | `/httppath/api%2Fv0%2Flogin` | |
| 21 | +| /tmp/foo/../bar | `/httppath/tmp%2Ffoo%2F..%2Fbar` | |
| 22 | +| a%20space | `/httppath/a%2520space` | |
| 23 | +| a%2Fslash | `/httppath/a%252Fslash` | |
30 | 24 |
|
31 | 25 | ## Usage
|
32 | 26 |
|
|
0 commit comments