@@ -986,10 +986,32 @@ impl<'a> Parser<'a> {
986
986
Ok ( ( host, input) )
987
987
}
988
988
989
- pub ( crate ) fn parse_file_host < ' i > (
989
+ pub fn get_file_host < ' i > ( input : Input < ' i > ) -> ParseResult < ( Host < String > , Input ) > {
990
+ let ( _, host_str, remaining) = Parser :: file_host ( input) ?;
991
+ let host = Host :: parse ( & host_str) ?;
992
+ Ok ( ( host, remaining) )
993
+ }
994
+
995
+ fn parse_file_host < ' i > (
990
996
& mut self ,
991
997
input : Input < ' i > ,
992
998
) -> ParseResult < ( bool , HostInternal , Input < ' i > ) > {
999
+ let ( has_host, host_str, remaining) = Parser :: file_host ( input) ?;
1000
+ let host = if host_str. is_empty ( ) {
1001
+ HostInternal :: None
1002
+ } else {
1003
+ match Host :: parse ( & host_str) ? {
1004
+ Host :: Domain ( ref d) if d == "localhost" => HostInternal :: None ,
1005
+ host => {
1006
+ write ! ( & mut self . serialization, "{}" , host) . unwrap ( ) ;
1007
+ host. into ( )
1008
+ }
1009
+ }
1010
+ } ;
1011
+ Ok ( ( has_host, host, remaining) )
1012
+ }
1013
+
1014
+ pub fn file_host < ' i > ( input : Input < ' i > ) -> ParseResult < ( bool , String , Input < ' i > ) > {
993
1015
// Undo the Input abstraction here to avoid allocating in the common case
994
1016
// where the host part of the input does not contain any tab or newline
995
1017
let input_str = input. chars . as_str ( ) ;
@@ -1018,20 +1040,9 @@ impl<'a> Parser<'a> {
1018
1040
}
1019
1041
}
1020
1042
if is_windows_drive_letter ( host_str) {
1021
- return Ok ( ( false , HostInternal :: None , input) ) ;
1043
+ return Ok ( ( false , "" . to_string ( ) , input) ) ;
1022
1044
}
1023
- let host = if host_str. is_empty ( ) {
1024
- HostInternal :: None
1025
- } else {
1026
- match Host :: parse ( host_str) ? {
1027
- Host :: Domain ( ref d) if d == "localhost" => HostInternal :: None ,
1028
- host => {
1029
- write ! ( & mut self . serialization, "{}" , host) . unwrap ( ) ;
1030
- host. into ( )
1031
- }
1032
- }
1033
- } ;
1034
- Ok ( ( true , host, remaining) )
1045
+ Ok ( ( true , host_str. to_string ( ) , remaining) )
1035
1046
}
1036
1047
1037
1048
pub fn parse_port < P > (
0 commit comments