yesod-static 1.2.3 → 1.2.4
raw patch · 3 files changed
+28/−4 lines, 3 filesdep +wai-extra
Dependencies added: wai-extra
Files
- Yesod/EmbeddedStatic.hs +5/−0
- Yesod/EmbeddedStatic/Internal.hs +21/−3
- yesod-static.cabal +2/−1
Yesod/EmbeddedStatic.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -89,7 +90,11 @@ resp = case pathInfo req of ("res":_) -> stApp site req ("widget":_) -> staticApp (widgetSettings site) req+#if MIN_VERSION_wai(3,0,0)+ _ -> ($ responseLBS status404 [] "Not Found")+#else _ -> return $ responseLBS status404 [] "Not Found"+#endif -- | Create the haskell variable for the link to the entry mkRoute :: ComputedEntry -> Q [Dec]
Yesod/EmbeddedStatic/Internal.hs view
@@ -106,12 +106,22 @@ } return $ ComputedEntry (ebHaskellName e) st link +toApp :: (Request -> IO Response) -> Application+#if MIN_VERSION_wai(3, 0, 0)+toApp f req g = f req >>= g+#else+toApp = id+#endif+ tryExtraDevelFiles :: [[T.Text] -> IO (Maybe (MimeType, BL.ByteString))] -> Application-tryExtraDevelFiles [] _ = return $ responseLBS status404 [] ""-tryExtraDevelFiles (f:fs) r = do+tryExtraDevelFiles = toApp . tryExtraDevelFiles'++tryExtraDevelFiles' :: [[T.Text] -> IO (Maybe (MimeType, BL.ByteString))] -> Request -> IO Response+tryExtraDevelFiles' [] _ = return $ responseLBS status404 [] ""+tryExtraDevelFiles' (f:fs) r = do mct <- liftIO $ f $ drop 1 $ pathInfo r -- drop the initial "res" case mct of- Nothing -> tryExtraDevelFiles fs r+ Nothing -> tryExtraDevelFiles' fs r Just (mime, ct) -> do let hash = T.encodeUtf8 $ T.pack $ base64md5 ct let headers = [ ("Content-Type", mime)@@ -123,11 +133,19 @@ -- | Helper to create the development application at runtime develApp :: StaticSettings -> [[T.Text] -> IO (Maybe (MimeType, BL.ByteString))] -> Application+#if MIN_VERSION_wai(3, 0, 0)+develApp settings extra req sendResponse = do+ staticApp settings {ssMaxAge = NoMaxAge} req $ \resp ->+ if statusCode (responseStatus resp) == 404+ then tryExtraDevelFiles extra req sendResponse+ else sendResponse resp+#else develApp settings extra req = do resp <- staticApp settings {ssMaxAge = NoMaxAge} req if statusCode (responseStatus resp) == 404 then tryExtraDevelFiles extra req else return resp+#endif -- | The type of 'addStaticContent' type AddStaticContent site = T.Text -> T.Text -> BL.ByteString
yesod-static.cabal view
@@ -1,5 +1,5 @@ name: yesod-static-version: 1.2.3+version: 1.2.4 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -82,6 +82,7 @@ , hspec >= 1.3 , yesod-test >= 1.2 , wai-test+ , wai-extra , HUnit -- copy from above