@@ -192,6 +192,11 @@ var good = []string{
192
192
"/ip4/127.0.0.1/tcp/127/wss" ,
193
193
"/ip4/127.0.0.1/tcp/127/webrtc-direct" ,
194
194
"/ip4/127.0.0.1/tcp/127/webrtc" ,
195
+ "/http-path/tmp%2Fbar" ,
196
+ "/http-path/tmp%2Fbar%2Fbaz" ,
197
+ "/http-path/foo" ,
198
+ "/ip4/127.0.0.1/tcp/0/p2p/12D3KooWCryG7Mon9orvQxcS1rYZjotPgpwoJNHHKcLLfE4Hf5mV/http-path/foo" ,
199
+ "/ip4/127.0.0.1/tcp/443/tls/sni/example.com/http/http-path/foo" ,
195
200
}
196
201
197
202
func TestConstructSucceeds (t * testing.T ) {
@@ -627,6 +632,7 @@ func TestRoundTrip(t *testing.T) {
627
632
"/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g" ,
628
633
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP" ,
629
634
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP/unix/a/b/c" ,
635
+ "/http-path/tmp%2Fbar" ,
630
636
} {
631
637
ma , err := NewMultiaddr (s )
632
638
if err != nil {
@@ -923,3 +929,48 @@ func TestDNS(t *testing.T) {
923
929
t .Fatal ("expected equality" )
924
930
}
925
931
}
932
+
933
+ func TestHTTPPath (t * testing.T ) {
934
+ t .Run ("bad addr" , func (t * testing.T ) {
935
+ badAddr := "/http-path/thisIsMissingAfullByte%f"
936
+ _ , err := NewMultiaddr (badAddr )
937
+ require .Error (t , err )
938
+ })
939
+
940
+ t .Run ("only reads the http-path part" , func (t * testing.T ) {
941
+ addr := "/http-path/tmp%2Fbar/p2p-circuit" // The http-path only reference the part immediately after it. It does not include the rest of the multiaddr (like the /path component sometimes does)
942
+ m , err := NewMultiaddr (addr )
943
+ require .NoError (t , err )
944
+ m .ValueForProtocol (P_HTTP_PATH )
945
+ v , err := m .ValueForProtocol (P_HTTP_PATH )
946
+ require .NoError (t , err )
947
+ require .Equal (t , "tmp%2Fbar" , v )
948
+ })
949
+
950
+ t .Run ("round trip" , func (t * testing.T ) {
951
+ cases := []string {
952
+ "/http-path/tmp%2Fbar" ,
953
+ "/http-path/tmp%2Fbar%2Fbaz" ,
954
+ "/http-path/foo" ,
955
+ "/ip4/127.0.0.1/tcp/0/p2p/12D3KooWCryG7Mon9orvQxcS1rYZjotPgpwoJNHHKcLLfE4Hf5mV/http-path/foo" ,
956
+ "/ip4/127.0.0.1/tcp/443/tls/sni/example.com/http/http-path/foo" ,
957
+ }
958
+ for _ , c := range cases {
959
+ m , err := NewMultiaddr (c )
960
+ require .NoError (t , err )
961
+ require .Equal (t , c , m .String ())
962
+ }
963
+ })
964
+
965
+ t .Run ("value for protocol" , func (t * testing.T ) {
966
+ m := StringCast ("/http-path/tmp%2Fbar" )
967
+ v , err := m .ValueForProtocol (P_HTTP_PATH )
968
+ require .NoError (t , err )
969
+ // This gives us the url escaped version
970
+ require .Equal (t , "tmp%2Fbar" , v )
971
+
972
+ // If we want the raw unescaped version, we can use the component and read it
973
+ _ , component := SplitLast (m )
974
+ require .Equal (t , "tmp/bar" , string (component .RawValue ()))
975
+ })
976
+ }
0 commit comments