@@ -1,15 +1,23 @@
11{-# LANGUAGE OverloadedStrings #-}
2−module Network.Wai.Middleware.CleanPath (cleanPath, cleanPathRel, splitPath) where
2+module Network.Wai.Middleware.CleanPath
3+ ( cleanPath
4+ , cleanPathRel
5+ , cleanPathFunc
6+ , splitPath
7+ ) where
38
49import Network.Wai
510import qualified Data.ByteString.Char8 as B
611import qualified Data.ByteString.Lazy as L
712import Network.URI (unEscapeString)
813
9−-- | Performs redirects as per 'splitPath'.
10−cleanPathRel :: B.ByteString -> ([String] -> Request -> IO Response) -> Request -> IO Response
11−cleanPathRel prefix app env =
12− case splitPath $ pathInfo env of
14+cleanPathFunc :: (B.ByteString -> Either B.ByteString [String])
15+ -> B.ByteString
16+ -> ([String] -> Request -> IO Response)
17+ -> Request
18+ -> IO Response
19+cleanPathFunc splitter prefix app env =
20+ case splitter $ pathInfo env of
1321 Right pieces -> app pieces env
1422 Left p -> return
1523 . Response status301
@@ -23,6 +31,11 @@ cleanPathRel prefix app env =
2331 Just ('?', _) -> queryString env
2432 _ -> B.cons '?' $ queryString env
2533
34+-- | Performs redirects as per 'splitPath'.
35+cleanPathRel :: B.ByteString -> ([String] -> Request -> IO Response)
36+ -> Request -> IO Response
37+cleanPathRel = cleanPathFunc splitPath
38+
2639cleanPath :: ([String] -> Request -> IO Response) -> Request -> IO Response
2740cleanPath = cleanPathRel B.empty
2841