on master help sign in
Do not strip a trailing slash from URI path
129ea3fJohan Förberg
CHANGELOG.md+5
@@ -1,3 +1,8 @@
1+## Req 3.9.0
2+
3+* The `useHttpURI` and `useHttpsURI` functions now preserve trailing
4+ slashes.
5+
1## Req 3.8.0
6## Req 3.8.0
2
7
3* Adjusted the value of the `httpConfigRetryJudgeException` field of
8* Adjusted the value of the `httpConfigRetryJudgeException` field of
Network/HTTP/Req.hs+14−4
@@ -1029,8 +1029,7 @@ useHttpURI uri = do
1029 urlHead <- http <$> uriHost uri
1029 urlHead <- http <$> uriHost uri
1030 let url = case URI.uriPath uri of
1030 let url = case URI.uriPath uri of
1031 Nothing -> urlHead
1031 Nothing -> urlHead
1032− Just (_, xs) ->
1032+ Just uriPath -> uriPathToUrl uriPath urlHead
1033− foldl' (/:) urlHead (URI.unRText <$> NE.toList xs)
1034 return (url, uriOptions uri)
1033 return (url, uriOptions uri)
1035
1034
1036-- | Just like 'useHttpURI', but expects the “https” scheme.
1035-- | Just like 'useHttpURI', but expects the “https” scheme.
@@ -1042,10 +1041,21 @@ useHttpsURI uri = do
1042 urlHead <- https <$> uriHost uri
1041 urlHead <- https <$> uriHost uri
1043 let url = case URI.uriPath uri of
1042 let url = case URI.uriPath uri of
1044 Nothing -> urlHead
1043 Nothing -> urlHead
1045− Just (_, xs) ->
1044+ Just uriPath -> uriPathToUrl uriPath urlHead
1046− foldl' (/:) urlHead (URI.unRText <$> NE.toList xs)
1047 return (url, uriOptions uri)
1045 return (url, uriOptions uri)
1048
1046
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+
1049-- | A combination of 'useHttpURI' and 'useHttpsURI' for cases when scheme
1059-- | A combination of 'useHttpURI' and 'useHttpsURI' for cases when scheme
1050-- is not known in advance.
1060-- is not known in advance.
1051--
1061--
pure-tests/Network/HTTP/ReqSpec.hsmode 100755 → 100644+3−2
@@ -565,8 +565,9 @@ uriPort def uri =
565-- | Get path from 'URI'.
565-- | Get path from 'URI'.
566uriPath :: URI -> ByteString
566uriPath :: URI -> ByteString
567uriPath uri = fromMaybe "" $ do
567uriPath uri = fromMaybe "" $ do
568− (_, xs) <- URI.uriPath uri
568+ (trailingSlash, xs) <- URI.uriPath uri
569− (return . encodePathPieces . fmap URI.unRText . NE.toList) xs
569+ let pref = (encodePathPieces . fmap URI.unRText . NE.toList) xs
570+ return $ if trailingSlash then pref <> "/" else pref
570
571
571-- | Get query string from 'URI'.
572-- | Get query string from 'URI'.
572uriQuery :: URI -> ByteString
573uriQuery :: URI -> ByteString