X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FStaticFile.hs;h=9175ce9289c816cdb4f8375195b9adf53efb2214;hb=70bf5bd248aa426ca4e410b3fb9a0529354aedaf;hp=608d608169dfa0bdcffbf24a1e600ef6baa8a1c3;hpb=4ff7f4b48f372e1cbea63873c5604ee3b4b56d09;p=Lucu.git diff --git a/Network/HTTP/Lucu/StaticFile.hs b/Network/HTTP/Lucu/StaticFile.hs index 608d608..9175ce9 100644 --- a/Network/HTTP/Lucu/StaticFile.hs +++ b/Network/HTTP/Lucu/StaticFile.hs @@ -1,3 +1,7 @@ +{-# LANGUAGE + BangPatterns + , UnicodeSyntax + #-} -- | Handling static files on the filesystem. module Network.HTTP.Lucu.StaticFile ( staticFile @@ -23,6 +27,7 @@ import Network.HTTP.Lucu.Resource import Network.HTTP.Lucu.Resource.Tree import Network.HTTP.Lucu.Response import Network.HTTP.Lucu.Utils +import System.FilePath.Posix import System.Posix.Files @@ -64,7 +69,7 @@ handleStaticFile path $ abort Forbidden [] Nothing -- 讀める tag <- liftIO $ generateETagFromFile path - lastMod <- return $ posixSecondsToUTCTime $ fromRational $ toRational $ modificationTime stat + let lastMod = posixSecondsToUTCTime $ fromRational $ toRational $ modificationTime stat foundEntity tag lastMod -- MIME Type を推定 @@ -74,7 +79,7 @@ handleStaticFile path Just mime -> setContentType mime -- 實際にファイルを讀んで送る - (liftIO $ B.readFile path) >>= outputLBS + liftIO (B.readFile path) >>= outputLBS else abort Forbidden [] Nothing else @@ -134,16 +139,15 @@ staticDir path -- 'Network.HTTP.Lucu.Resource.Tree.ResTree', you had better use -- 'staticDir' instead of this. handleStaticDir :: FilePath -> Resource () -handleStaticDir basePath - = basePath `seq` - do extraPath <- getPathInfo +handleStaticDir !basePath + = do extraPath <- getPathInfo securityCheck extraPath - let path = basePath ++ "/" ++ joinWith "/" extraPath + let path = basePath joinPath extraPath handleStaticFile path where securityCheck :: Monad m => [String] -> m () - securityCheck pathElems - = pathElems `seq` - when (any (== "..") pathElems) $ fail ("security error: " + securityCheck !pathElems + = when (any (== "..") pathElems) $ fail ("security error: " ++ joinWith "/" pathElems) +-- TODO: implement directory listing.