@@ -1029,8 +1029,7 @@ useHttpURI uri = do
10291029 urlHead <- http <$> uriHost uri
10301030 let url = case URI.uriPath uri of
10311031 Nothing -> urlHead
1032− Just (_, xs) ->
1033− foldl' (/:) urlHead (URI.unRText <$> NE.toList xs)
1032+ Just uriPath -> uriPathToUrl uriPath urlHead
10341033 return (url, uriOptions uri)
10351034
10361035-- | Just like 'useHttpURI', but expects the “https” scheme.
@@ -1042,10 +1041,21 @@ useHttpsURI uri = do
10421041 urlHead <- https <$> uriHost uri
10431042 let url = case URI.uriPath uri of
10441043 Nothing -> urlHead
1045− Just (_, xs) ->
1046− foldl' (/:) urlHead (URI.unRText <$> NE.toList xs)
1044+ Just uriPath -> uriPathToUrl uriPath urlHead
10471045 return (url, uriOptions uri)
10481046
1047+-- | Convert URI path to a 'Url'. Internal.
1048+--
1049+-- @since 3.9.0
1050+uriPathToUrl ::
1051+ (Bool, NonEmpty (URI.RText 'URI.PathPiece)) ->
1052+ Url scheme ->
1053+ Url scheme
1054+uriPathToUrl (trailingSlash, xs) urlHead =
1055+ if trailingSlash then path /: T.empty else path
1056+ where
1057+ path = foldl' (/:) urlHead (URI.unRText <$> NE.toList xs)
1058+
10491059-- | A combination of 'useHttpURI' and 'useHttpsURI' for cases when scheme
10501060-- is not known in advance.
10511061--