Skip to content

Commit 8293d85

Browse files
authored
fix: prefer /tls/http to /https and /tls/ws to /wss (#56)
The [HTTP spec](https://github.com/libp2p/specs/tree/master/http) settled on `/tls/http` over `/https` to allow including things like `/sni` in the multiaddr, so return `/tls/http` in favour of `/https` here. Fixes #6
1 parent 5e30ecb commit 8293d85

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ function tupleForScheme (scheme: string): [string] | undefined {
181181
return undefined
182182
}
183183

184+
if (scheme === 'https') {
185+
return ['/tls/http']
186+
}
187+
188+
if (scheme === 'wss') {
189+
return ['/tls/ws']
190+
}
191+
184192
return [scheme]
185193
}
186194

test/test.spec.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('uri-to-multiaddr', () => {
99
['/ip6/fc00::/tcp/80/http', 'http://[fc00::]'],
1010
['/ip4/0.0.7.6/tcp/1234', 'tcp://0.0.7.6:1234'],
1111
['/ip4/0.0.7.6/tcp/1234/http', 'http://0.0.7.6:1234'],
12-
['/ip4/0.0.7.6/tcp/1234/https', 'https://0.0.7.6:1234'],
12+
['/ip4/0.0.7.6/tcp/1234/tls/http', 'https://0.0.7.6:1234'],
1313
['/ip6/::/tcp/0', 'tcp://[::]:0'],
1414
['/ip4/0.0.7.6/udp/1234', 'udp://0.0.7.6:1234'],
1515
['/ip6/::/udp/0', 'udp://[::]:0'],
@@ -33,14 +33,14 @@ describe('uri-to-multiaddr', () => {
3333
['/dnsaddr/protocol.ai/tcp/80/http', 'http://protocol.ai:80', {
3434
defaultDnsType: 'dnsaddr'
3535
}],
36-
['/dns/protocol.ai/tcp/80/https', 'https://protocol.ai:80'],
37-
['/dns4/protocol.ai/tcp/80/https', 'https://protocol.ai:80', {
36+
['/dns/protocol.ai/tcp/80/tls/http', 'https://protocol.ai:80'],
37+
['/dns4/protocol.ai/tcp/80/tls/http', 'https://protocol.ai:80', {
3838
defaultDnsType: 'dns4'
3939
}],
40-
['/dns6/protocol.ai/tcp/80/https', 'https://protocol.ai:80', {
40+
['/dns6/protocol.ai/tcp/80/tls/http', 'https://protocol.ai:80', {
4141
defaultDnsType: 'dns6'
4242
}],
43-
['/dnsaddr/protocol.ai/tcp/80/https', 'https://protocol.ai:80', {
43+
['/dnsaddr/protocol.ai/tcp/80/tls/http', 'https://protocol.ai:80', {
4444
defaultDnsType: 'dnsaddr'
4545
}],
4646
['/dns/ipfs.io/tcp/80/ws', 'ws://ipfs.io'],
@@ -53,14 +53,14 @@ describe('uri-to-multiaddr', () => {
5353
['/dnsaddr/ipfs.io/tcp/80/ws', 'ws://ipfs.io', {
5454
defaultDnsType: 'dnsaddr'
5555
}],
56-
['/dns/ipfs.io/tcp/443/wss', 'wss://ipfs.io'],
57-
['/dns4/ipfs.io/tcp/443/wss', 'wss://ipfs.io', {
56+
['/dns/ipfs.io/tcp/443/tls/ws', 'wss://ipfs.io'],
57+
['/dns4/ipfs.io/tcp/443/tls/ws', 'wss://ipfs.io', {
5858
defaultDnsType: 'dns4'
5959
}],
60-
['/dns6/ipfs.io/tcp/443/wss', 'wss://ipfs.io', {
60+
['/dns6/ipfs.io/tcp/443/tls/ws', 'wss://ipfs.io', {
6161
defaultDnsType: 'dns6'
6262
}],
63-
['/dnsaddr/ipfs.io/tcp/443/wss', 'wss://ipfs.io', {
63+
['/dnsaddr/ipfs.io/tcp/443/tls/ws', 'wss://ipfs.io', {
6464
defaultDnsType: 'dnsaddr'
6565
}],
6666
['/dns/ipfs.io/tcp/80/http', 'http://ipfs.io'],
@@ -73,24 +73,24 @@ describe('uri-to-multiaddr', () => {
7373
['/dnsaddr/ipfs.io/tcp/80/http', 'http://ipfs.io', {
7474
defaultDnsType: 'dnsaddr'
7575
}],
76-
['/dns/ipfs.io/tcp/443/https', 'https://ipfs.io'],
77-
['/dns4/ipfs.io/tcp/443/https', 'https://ipfs.io', {
76+
['/dns/ipfs.io/tcp/443/tls/http', 'https://ipfs.io'],
77+
['/dns4/ipfs.io/tcp/443/tls/http', 'https://ipfs.io', {
7878
defaultDnsType: 'dns4'
7979
}],
80-
['/dns6/ipfs.io/tcp/443/https', 'https://ipfs.io', {
80+
['/dns6/ipfs.io/tcp/443/tls/http', 'https://ipfs.io', {
8181
defaultDnsType: 'dns6'
8282
}],
83-
['/dnsaddr/ipfs.io/tcp/443/https', 'https://ipfs.io', {
83+
['/dnsaddr/ipfs.io/tcp/443/tls/http', 'https://ipfs.io', {
8484
defaultDnsType: 'dnsaddr'
8585
}],
86-
['/dns/ipfs.io/tcp/443/https', 'https://ipfs.io:443'],
87-
['/dns4/ipfs.io/tcp/443/https', 'https://ipfs.io:443', {
86+
['/dns/ipfs.io/tcp/443/tls/http', 'https://ipfs.io:443'],
87+
['/dns4/ipfs.io/tcp/443/tls/http', 'https://ipfs.io:443', {
8888
defaultDnsType: 'dns4'
8989
}],
90-
['/dns6/ipfs.io/tcp/443/https', 'https://ipfs.io:443', {
90+
['/dns6/ipfs.io/tcp/443/tls/http', 'https://ipfs.io:443', {
9191
defaultDnsType: 'dns6'
9292
}],
93-
['/dnsaddr/ipfs.io/tcp/443/https', 'https://ipfs.io:443', {
93+
['/dnsaddr/ipfs.io/tcp/443/tls/http', 'https://ipfs.io:443', {
9494
defaultDnsType: 'dnsaddr'
9595
}],
9696
['/dns/ipfs.io/tcp/443', 'tcp://ipfs.io:443'],
@@ -114,18 +114,18 @@ describe('uri-to-multiaddr', () => {
114114
defaultDnsType: 'dnsaddr'
115115
}],
116116
['/ip4/1.2.3.4/tcp/3456/ws', 'ws://1.2.3.4:3456'],
117-
['/ip4/1.2.3.4/tcp/3456/wss', 'wss://1.2.3.4:3456'],
117+
['/ip4/1.2.3.4/tcp/3456/tls/ws', 'wss://1.2.3.4:3456'],
118118
['/ip6/::/tcp/0/ws', 'ws://[::]:0'],
119-
['/ip4/1.2.3.4/tcp/3456/wss', 'wss://1.2.3.4:3456'],
120-
['/ip6/::/tcp/0/wss', 'wss://[::]:0'],
121-
['/dns/example.com/tcp/443/wss/http-path/foo', 'wss://example.com:443/foo'],
122-
['/dns4/example.com/tcp/443/wss/http-path/foo', 'wss://example.com:443/foo', {
119+
['/ip4/1.2.3.4/tcp/3456/tls/ws', 'wss://1.2.3.4:3456'],
120+
['/ip6/::/tcp/0/tls/ws', 'wss://[::]:0'],
121+
['/dns/example.com/tcp/443/tls/ws/http-path/foo', 'wss://example.com:443/foo'],
122+
['/dns4/example.com/tcp/443/tls/ws/http-path/foo', 'wss://example.com:443/foo', {
123123
defaultDnsType: 'dns4'
124124
}],
125-
['/dns6/example.com/tcp/443/wss/http-path/foo', 'wss://example.com:443/foo', {
125+
['/dns6/example.com/tcp/443/tls/ws/http-path/foo', 'wss://example.com:443/foo', {
126126
defaultDnsType: 'dns6'
127127
}],
128-
['/dnsaddr/example.com/tcp/443/wss/http-path/foo', 'wss://example.com:443/foo', {
128+
['/dnsaddr/example.com/tcp/443/tls/ws/http-path/foo', 'wss://example.com:443/foo', {
129129
defaultDnsType: 'dnsaddr'
130130
}]
131131
]
@@ -143,7 +143,7 @@ describe('uri-to-multiaddr', () => {
143143
const data: Array<[string, string, MultiaddrFromUriOpts]> = [
144144
['/dns4/protocol.ai/tcp/80', 'tcp://protocol.ai:80', { defaultDnsType: 'dns4' }],
145145
['/dns6/protocol.ai/tcp/80/http', 'http://protocol.ai:80', { defaultDnsType: 'dns6' }],
146-
['/dnsaddr/protocol.ai/tcp/80/https', 'https://protocol.ai:80', { defaultDnsType: 'dnsaddr' }]
146+
['/dnsaddr/protocol.ai/tcp/80/tls/http', 'https://protocol.ai:80', { defaultDnsType: 'dnsaddr' }]
147147
]
148148

149149
data.forEach(d => {

0 commit comments

Comments
 (0)