File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,16 @@ impl IpAddrs {
228
228
let addr = SocketAddrV4 :: new ( addr, port) ;
229
229
return Some ( IpAddrs { iter : vec ! [ SocketAddr :: V4 ( addr) ] . into_iter ( ) } )
230
230
}
231
+ let host = {
232
+ // trim_left/trim_right deprecated...
233
+ // TODO: use trim_start/trim_end in Rust 1.30
234
+ #[ allow( deprecated) ]
235
+ {
236
+ host
237
+ . trim_left_matches ( '[' )
238
+ . trim_right_matches ( ']' )
239
+ }
240
+ } ;
231
241
if let Ok ( addr) = host. parse :: < Ipv6Addr > ( ) {
232
242
let addr = SocketAddrV6 :: new ( addr, port, 0 , 0 ) ;
233
243
return Some ( IpAddrs { iter : vec ! [ SocketAddr :: V6 ( addr) ] . into_iter ( ) } )
@@ -360,4 +370,19 @@ mod tests {
360
370
assert_eq ! ( name. as_str( ) , DOMAIN ) ;
361
371
assert_eq ! ( name. to_string( ) , DOMAIN ) ;
362
372
}
373
+
374
+ #[ test]
375
+ fn ip_addrs_try_parse_v6 ( ) {
376
+ let uri = :: http:: Uri :: from_static ( "http://[::1]:8080/" ) ;
377
+ let dst = super :: super :: Destination { uri } ;
378
+
379
+ let mut addrs = IpAddrs :: try_parse (
380
+ dst. host ( ) ,
381
+ dst. port ( ) . expect ( "port" )
382
+ ) . expect ( "try_parse" ) ;
383
+
384
+ let expected = "[::1]:8080" . parse :: < SocketAddr > ( ) . expect ( "expected" ) ;
385
+
386
+ assert_eq ! ( addrs. next( ) , Some ( expected) ) ;
387
+ }
363
388
}
You can’t perform that action at this time.
0 commit comments