packages feed

wai-middleware-static 0.1.0 → 0.1.1

raw patch · 2 files changed

+13/−3 lines, 2 files

Files

Network/Wai/Middleware/Static.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE OverloadedStrings #-}-module Network.Wai.Middleware.Static (static, staticRoot) where+module Network.Wai.Middleware.Static (static, staticRoot, staticList) where +import Control.Monad (mplus) import Control.Monad.Trans (liftIO) import Data.List (isInfixOf) import qualified Data.Map as M@@ -32,8 +33,17 @@               if exists                 then return $ ResponseFile status200 [("Content-Type", getMimeType fp)] fStr Nothing                 else app req-  where fp = F.collapse $ F.fromText $ T.dropWhile (=='/') $ E.decodeUtf8 $ rawPathInfo req+  where fp = F.collapse $ F.fromText $ T.intercalate "/" $ pathInfo req         fStr = F.encodeString $ F.fromText base F.</> fp++-- | Serve only the files given in an association list.+-- Key is the URI, Value is the filesystem path.+staticList :: [(T.Text, T.Text)] -> Middleware+staticList fs app req =+    maybe (app req)+          (\fp -> return $ ResponseFile status200 [("Content-Type", getMimeType (F.fromText fp))] (T.unpack fp) Nothing)+          ((lookup p fs) `mplus` (lookup (T.cons '/' p) fs)) -- try without and with leading slash+    where p = (T.intercalate "/" $ pathInfo req)  getMimeType :: F.FilePath -> B.ByteString getMimeType = go . map E.encodeUtf8 . F.extensions
wai-middleware-static.cabal view
@@ -1,5 +1,5 @@ Name:                wai-middleware-static-Version:             0.1.0+Version:             0.1.1 Synopsis:            WAI middleware that intercepts requests to static files. Homepage:            https://github.com/xich/scotty Bug-reports:         https://github.com/xich/scotty/issues