|
| 1 | +# `httppath` |
| 2 | + |
| 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. |
| 16 | + |
| 17 | +When comparing multiaddrs, implementations should compare their binary |
| 18 | +representation to avoid ambiguities over which characters were escaped. |
| 19 | + |
| 20 | +## Reserved Characters |
| 21 | + |
| 22 | +| Character | Reason | |
| 23 | +| --------- | ----------------------------- | |
| 24 | +| / | Multiaddr component separator | |
| 25 | +| % | Percent encoding indicator | |
| 26 | +| ? | Marks the end of an HTTP path | |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +`/httppath` should be appended to the end of an existing multiaddr, including after the peer id component (p2p). As an example, here's a multiaddr referencing the `.well-known/libp2p` HTTP resource along with a way to reach that peer: |
| 31 | + |
| 32 | +``` |
| 33 | +/ip4/1.2.3.4/tcp/443/tls/http/p2p/12D.../httppath/.well-known%2Flibp2p |
| 34 | +``` |
| 35 | + |
| 36 | +The `/httppath` component can also be appended to just the `/p2p/...` component, and rely on a separate peer discovery mechanism to actually identify the peer's address: |
| 37 | + |
| 38 | +``` |
| 39 | +/ip4/1.2.3.4/tcp/443/tls/http/p2p/12D.../httppath/.well-known%2Flibp2p |
| 40 | +``` |
0 commit comments