File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -160,11 +160,20 @@ pub fn is_host_valid(host: Option<&str>, allowed_hosts: &Option<Vec<Host>>) -> b
160
160
161
161
/// Updates given list of hosts with the address.
162
162
pub fn update ( hosts : Option < Vec < Host > > , address : & SocketAddr ) -> Option < Vec < Host > > {
163
+ use std:: net:: { IpAddr , Ipv4Addr } ;
164
+
163
165
hosts. map ( |current_hosts| {
164
166
let mut new_hosts = current_hosts. into_iter ( ) . collect :: < HashSet < _ > > ( ) ;
165
- let address = address. to_string ( ) ;
166
- new_hosts. insert ( address. clone ( ) . into ( ) ) ;
167
- new_hosts. insert ( address. replace ( "127.0.0.1" , "localhost" ) . into ( ) ) ;
167
+ let address_string = address. to_string ( ) ;
168
+
169
+ if address. ip ( ) == IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) {
170
+ new_hosts. insert ( address_string. replace ( "0.0.0.0" , "127.0.0.1" ) . into ( ) ) ;
171
+ new_hosts. insert ( address_string. replace ( "0.0.0.0" , "localhost" ) . into ( ) ) ;
172
+ } else if address. ip ( ) == IpAddr :: V4 ( Ipv4Addr :: LOCALHOST ) {
173
+ new_hosts. insert ( address_string. replace ( "127.0.0.1" , "localhost" ) . into ( ) ) ;
174
+ }
175
+
176
+ new_hosts. insert ( address_string. into ( ) ) ;
168
177
new_hosts. into_iter ( ) . collect ( )
169
178
} )
170
179
}
You can’t perform that action at this time.
0 commit comments