Skip to content

Commit a20267c

Browse files
committed
Define httppath component
1 parent 358b3f8 commit a20267c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

protocols.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ code, size, name, comment
2828
465, 0, webtransport,
2929
466, V, certhash,
3030
480, 0, http, HyperText Transfer Protocol
31+
481, V, httppath, Percent-encoded path to an HTTP resource
3132
443, 0, https, Deprecated alias for /tls/http
3233
477, 0, ws, WebSockets
3334
478, 0, wss, Deprecated alias for /tls/ws

protocols/httppath.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)