wai-extra 0.1.2.1 → 0.1.3
raw patch · 2 files changed
+18/−14 lines, 2 files
Files
- Network/Wai/Middleware/CleanPath.hs +17/−13
- wai-extra.cabal +1/−1
Network/Wai/Middleware/CleanPath.hs view
@@ -1,24 +1,28 @@-module Network.Wai.Middleware.CleanPath (cleanPath, splitPath) where+module Network.Wai.Middleware.CleanPath (cleanPath, cleanPathRel, splitPath) where import Network.Wai import qualified Data.ByteString.Char8 as B import Network.URI (unEscapeString) -- | Performs redirects as per 'splitPath'.-cleanPath :: ([String] -> Request -> IO Response)- -> Request- -> IO Response-cleanPath app env =+cleanPathRel :: B.ByteString -> ([String] -> Request -> IO Response) -> Request -> IO Response+cleanPathRel prefix app env = case splitPath $ pathInfo env of- Left p -> do- -- include the query string if present- let suffix = case B.uncons $ queryString env of- Nothing -> B.empty- Just ('?', _) -> queryString env- _ -> B.cons '?' $ queryString env- return $ Response Status303 [(Location, B.append p suffix)]- $ Right emptyEnum Right pieces -> app pieces env+ Left p -> return+ . Response Status301+ [(Location, B.concat [prefix, p, suffix])]+ $ Right emptyEnum+ where+ -- include the query string if present+ suffix =+ case B.uncons $ queryString env of+ Nothing -> B.empty+ Just ('?', _) -> queryString env+ _ -> B.cons '?' $ queryString env++cleanPath :: ([String] -> Request -> IO Response) -> Request -> IO Response+cleanPath = cleanPathRel B.empty emptyEnum :: Enumerator emptyEnum = Enumerator $ \_ -> return . Right
wai-extra.cabal view
@@ -1,5 +1,5 @@ Name: wai-extra-Version: 0.1.2.1+Version: 0.1.3 Synopsis: Provides some basic WAI handlers and middleware. Description: The goal here is to provide common features without many dependencies. License: BSD3