@@ -968,10 +968,32 @@ impl<'a> Parser<'a> {
968
968
Ok ( ( host, input) )
969
969
}
970
970
971
- pub fn parse_file_host < ' i > (
971
+ pub fn get_file_host < ' i > ( input : Input < ' i > ) -> ParseResult < ( Host < String > , Input ) > {
972
+ let ( _, host_str, remaining) = Parser :: file_host ( input) ?;
973
+ let host = Host :: parse ( & host_str) ?;
974
+ Ok ( ( host, remaining) )
975
+ }
976
+
977
+ fn parse_file_host < ' i > (
972
978
& mut self ,
973
979
input : Input < ' i > ,
974
980
) -> ParseResult < ( bool , HostInternal , Input < ' i > ) > {
981
+ let ( has_host, host_str, remaining) = Parser :: file_host ( input) ?;
982
+ let host = if host_str. is_empty ( ) {
983
+ HostInternal :: None
984
+ } else {
985
+ match Host :: parse ( & host_str) ? {
986
+ Host :: Domain ( ref d) if d == "localhost" => HostInternal :: None ,
987
+ host => {
988
+ write ! ( & mut self . serialization, "{}" , host) . unwrap ( ) ;
989
+ host. into ( )
990
+ }
991
+ }
992
+ } ;
993
+ Ok ( ( has_host, host, remaining) )
994
+ }
995
+
996
+ pub fn file_host < ' i > ( input : Input < ' i > ) -> ParseResult < ( bool , String , Input < ' i > ) > {
975
997
// Undo the Input abstraction here to avoid allocating in the common case
976
998
// where the host part of the input does not contain any tab or newline
977
999
let input_str = input. chars . as_str ( ) ;
@@ -1000,20 +1022,9 @@ impl<'a> Parser<'a> {
1000
1022
}
1001
1023
}
1002
1024
if is_windows_drive_letter ( host_str) {
1003
- return Ok ( ( false , HostInternal :: None , input) ) ;
1025
+ return Ok ( ( false , "" . to_string ( ) , input) ) ;
1004
1026
}
1005
- let host = if host_str. is_empty ( ) {
1006
- HostInternal :: None
1007
- } else {
1008
- match Host :: parse ( host_str) ? {
1009
- Host :: Domain ( ref d) if d == "localhost" => HostInternal :: None ,
1010
- host => {
1011
- write ! ( & mut self . serialization, "{}" , host) . unwrap ( ) ;
1012
- host. into ( )
1013
- }
1014
- }
1015
- } ;
1016
- Ok ( ( true , host, remaining) )
1027
+ Ok ( ( true , host_str. to_string ( ) , remaining) )
1017
1028
}
1018
1029
1019
1030
pub fn parse_port < P > (
0 commit comments