@@ -36,35 +36,39 @@ func TestToSubdomainURL(t *testing.T) {
3636
3737 for _ , test := range []struct {
3838 // in:
39- request * http.Request
40- gwHostname string
41- path string
39+ request * http.Request
40+ gwHostname string
41+ inlineDNSLink bool
42+ path string
4243 // out:
4344 url string
4445 err error
4546 }{
4647 // DNSLink
47- {httpRequest , "localhost" , "/ipns/dnslink.io" , "http://dnslink.io.ipns.localhost/" , nil },
48+ {httpRequest , "localhost" , false , "/ipns/dnslink.io" , "http://dnslink.io.ipns.localhost/" , nil },
4849 // Hostname with port
49- {httpRequest , "localhost:8080" , "/ipns/dnslink.io" , "http://dnslink.io.ipns.localhost:8080/" , nil },
50+ {httpRequest , "localhost:8080" , false , "/ipns/dnslink.io" , "http://dnslink.io.ipns.localhost:8080/" , nil },
5051 // CIDv0 → CIDv1base32
51- {httpRequest , "localhost" , "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n" , "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.localhost/" , nil },
52+ {httpRequest , "localhost" , false , "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n" , "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.localhost/" , nil },
5253 // CIDv1 with long sha512
53- {httpRequest , "localhost" , "/ipfs/bafkrgqe3ohjcjplc6n4f3fwunlj6upltggn7xqujbsvnvyw764srszz4u4rshq6ztos4chl4plgg4ffyyxnayrtdi5oc4xb2332g645433aeg" , "" , errors .New ("CID incompatible with DNS label length limit of 63: kf1siqrebi3vir8sab33hu5vcy008djegvay6atmz91ojesyjs8lx350b7y7i1nvyw2haytfukfyu2f2x4tocdrfa0zgij6p4zpl4u5oj" )},
54+ {httpRequest , "localhost" , false , "/ipfs/bafkrgqe3ohjcjplc6n4f3fwunlj6upltggn7xqujbsvnvyw764srszz4u4rshq6ztos4chl4plgg4ffyyxnayrtdi5oc4xb2332g645433aeg" , "" , errors .New ("CID incompatible with DNS label length limit of 63: kf1siqrebi3vir8sab33hu5vcy008djegvay6atmz91ojesyjs8lx350b7y7i1nvyw2haytfukfyu2f2x4tocdrfa0zgij6p4zpl4u5oj" )},
5455 // PeerID as CIDv1 needs to have libp2p-key multicodec
55- {httpRequest , "localhost" , "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD" , "http://k2k4r8n0flx3ra0y5dr8fmyvwbzy3eiztmtq6th694k5a3rznayp3e4o.ipns.localhost/" , nil },
56- {httpRequest , "localhost" , "/ipns/bafybeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm" , "http://k2k4r8l9ja7hkzynavdqup76ou46tnvuaqegbd04a4o1mpbsey0meucb.ipns.localhost/" , nil },
56+ {httpRequest , "localhost" , false , "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD" , "http://k2k4r8n0flx3ra0y5dr8fmyvwbzy3eiztmtq6th694k5a3rznayp3e4o.ipns.localhost/" , nil },
57+ {httpRequest , "localhost" , false , "/ipns/bafybeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm" , "http://k2k4r8l9ja7hkzynavdqup76ou46tnvuaqegbd04a4o1mpbsey0meucb.ipns.localhost/" , nil },
5758 // PeerID: ed25519+identity multihash → CIDv1Base36
58- {httpRequest , "localhost" , "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5" , "http://k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna.ipns.localhost/" , nil },
59- {httpRequest , "sub.localhost" , "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n" , "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.sub.localhost/" , nil },
59+ {httpRequest , "localhost" , false , "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5" , "http://k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna.ipns.localhost/" , nil },
60+ {httpRequest , "sub.localhost" , false , "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n" , "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.sub.localhost/" , nil },
6061 // HTTPS requires DNSLink name to fit in a single DNS label – see "Option C" from https://github.com/ipfs/in-web-browsers/issues/169
61- {httpRequest , "dweb.link" , "/ipns/dnslink.long-name.example.com" , "http://dnslink.long-name.example.com.ipns.dweb.link/" , nil },
62- {httpsRequest , "dweb.link" , "/ipns/dnslink.long-name.example.com" , "https://dnslink-long--name-example-com.ipns.dweb.link/" , nil },
63- {httpsProxiedRequest , "dweb.link" , "/ipns/dnslink.long-name.example.com" , "https://dnslink-long--name-example-com.ipns.dweb.link/" , nil },
62+ {httpRequest , "dweb.link" , false , "/ipns/dnslink.long-name.example.com" , "http://dnslink.long-name.example.com.ipns.dweb.link/" , nil },
63+ {httpsRequest , "dweb.link" , false , "/ipns/dnslink.long-name.example.com" , "https://dnslink-long--name-example-com.ipns.dweb.link/" , nil },
64+ {httpsProxiedRequest , "dweb.link" , false , "/ipns/dnslink.long-name.example.com" , "https://dnslink-long--name-example-com.ipns.dweb.link/" , nil },
65+ // HTTP requests can also be converted to fit into a single DNS label - https://github.com/ipfs/kubo/issues/9243
66+ {httpRequest , "localhost" , true , "/ipns/dnslink.long-name.example.com" , "http://dnslink-long--name-example-com.ipns.localhost/" , nil },
67+ {httpRequest , "dweb.link" , true , "/ipns/dnslink.long-name.example.com" , "http://dnslink-long--name-example-com.ipns.dweb.link/" , nil },
6468 } {
65- url , err := toSubdomainURL (test .gwHostname , test .path , test .request , coreAPI )
69+ url , err := toSubdomainURL (test .gwHostname , test .path , test .request , test . inlineDNSLink , coreAPI )
6670 if url != test .url || ! equalError (err , test .err ) {
67- t .Errorf ("(%s, %s) returned (%s, %v), expected (%s, %v)" , test .gwHostname , test .path , url , err , test .url , test .err )
71+ t .Errorf ("(%s, %v, % s) returned (%s, %v), expected (%s, %v)" , test .gwHostname , test . inlineDNSLink , test .path , url , err , test .url , test .err )
6872 }
6973 }
7074}
0 commit comments