@@ -58,6 +58,7 @@ const GARLIC32: u32 = 447;
5858const SNI : u32 = 449 ;
5959const P2P_STARDUST : u32 = 277 ; // Deprecated
6060const WEBRTC : u32 = 281 ;
61+ const HTTP_PATH : u32 = 481 ;
6162
6263/// Type-alias for how multi-addresses use `Multihash`.
6364///
@@ -128,6 +129,7 @@ pub enum Protocol<'a> {
128129 Sni ( Cow < ' a , str > ) ,
129130 P2pStardust ,
130131 WebRTC ,
132+ HttpPath ( Cow < ' a , str > ) ,
131133}
132134
133135impl < ' a > Protocol < ' a > {
@@ -276,6 +278,11 @@ impl<'a> Protocol<'a> {
276278 }
277279 "p2p-stardust" => Ok ( Protocol :: P2pStardust ) ,
278280 "webrtc" => Ok ( Protocol :: WebRTC ) ,
281+ "http-path" => {
282+ let s = iter. next ( ) . ok_or ( Error :: InvalidProtocolString ) ?;
283+ let decoded = percent_encoding:: percent_decode ( s. as_bytes ( ) ) . decode_utf8 ( ) ?;
284+ Ok ( Protocol :: HttpPath ( decoded) )
285+ }
279286 unknown => Err ( Error :: UnknownProtocolString ( unknown. to_string ( ) ) ) ,
280287 }
281288 }
@@ -457,6 +464,14 @@ impl<'a> Protocol<'a> {
457464 }
458465 P2P_STARDUST => Ok ( ( Protocol :: P2pStardust , input) ) ,
459466 WEBRTC => Ok ( ( Protocol :: WebRTC , input) ) ,
467+ HTTP_PATH => {
468+ let ( n, input) = decode:: usize ( input) ?;
469+ let ( data, rest) = split_at ( n, input) ?;
470+ Ok ( (
471+ Protocol :: HttpPath ( Cow :: Borrowed ( str:: from_utf8 ( data) ?) ) ,
472+ rest,
473+ ) )
474+ }
460475 _ => Err ( Error :: UnknownProtocolId ( id) ) ,
461476 }
462477 }
@@ -604,6 +619,12 @@ impl<'a> Protocol<'a> {
604619 }
605620 Protocol :: P2pStardust => w. write_all ( encode:: u32 ( P2P_STARDUST , & mut buf) ) ?,
606621 Protocol :: WebRTC => w. write_all ( encode:: u32 ( WEBRTC , & mut buf) ) ?,
622+ Protocol :: HttpPath ( s) => {
623+ w. write_all ( encode:: u32 ( HTTP_PATH , & mut buf) ) ?;
624+ let bytes = s. as_bytes ( ) ;
625+ w. write_all ( encode:: usize ( bytes. len ( ) , & mut encode:: usize_buffer ( ) ) ) ?;
626+ w. write_all ( bytes) ?
627+ }
607628 }
608629 Ok ( ( ) )
609630 }
@@ -651,6 +672,7 @@ impl<'a> Protocol<'a> {
651672 Sni ( cow) => Sni ( Cow :: Owned ( cow. into_owned ( ) ) ) ,
652673 P2pStardust => P2pStardust ,
653674 WebRTC => WebRTC ,
675+ HttpPath ( cow) => HttpPath ( Cow :: Owned ( cow. into_owned ( ) ) ) ,
654676 }
655677 }
656678
@@ -698,6 +720,7 @@ impl<'a> Protocol<'a> {
698720 Sni ( _) => "sni" ,
699721 P2pStardust => "p2p-stardust" ,
700722 WebRTC => "webrtc" ,
723+ HttpPath ( _) => "http-path" ,
701724 }
702725 }
703726}
@@ -755,6 +778,11 @@ impl<'a> fmt::Display for Protocol<'a> {
755778 ) ,
756779 Garlic32 ( addr) => write ! ( f, "/{}" , multibase:: Base :: Base32Lower . encode( addr) ) ,
757780 Sni ( s) => write ! ( f, "/{s}" ) ,
781+ HttpPath ( s) => {
782+ let encoded =
783+ percent_encoding:: percent_encode ( s. as_bytes ( ) , PATH_SEGMENT_ENCODE_SET ) ;
784+ write ! ( f, "/{encoded}" )
785+ }
758786 _ => Ok ( ( ) ) ,
759787 }
760788 }
0 commit comments