on master help sign in
cleanPathFunc
commit734c69697484bb89349bd0c6fea24aaf7c09e0fe authorMichael Snoyman <michael@snoyman.com> dateWed 4 Aug 2010, 21:34 (16 years ago) parentdf721d5
2 files changed+19−6
Network/Wai/Middleware/CleanPath.hs+18−5 wai-extra.cabal+1−1
Network/Wai/Middleware/CleanPath.hs+18−5
@@ -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
wai-extra.cabal+1−1
@@ -1,5 +1,5 @@
11Name: wai-extra
2−Version: 0.2.1
2+Version: 0.2.2
33Synopsis: Provides some basic WAI handlers and middleware.
44Description: The goal here is to provide common features without many dependencies.
55License: BSD3