+-- -*- Coding: utf-8 -*-
module Rakka.Resource.Object
( resObject
)
where
-import Data.ByteString.Char8 as C8
import Data.Maybe
import Network.HTTP.Lucu
import Network.HTTP.Lucu.Utils
import Rakka.Page
import Rakka.Storage
import Rakka.SystemConfig
-import System.Time
resObject :: Environment -> ResourceDef
handleGet env name
= do pageM <- getPage (envStorage env) name Nothing
case pageM of
- Nothing
- -> foundNoEntity Nothing
-
- Just redir@(Redirection _ _ _ _)
- -> handleRedirect env redir
-
- Just entity@(Entity _ _ _ _ _ _ _ _ _ _ _ _ _ _)
- -> handleGetEntity env entity
+ Nothing -> foundNoEntity Nothing
+ Just page -> if isEntity page then
+ handleGetEntity page
+ else
+ handleRedirect env page
{-
...
-}
-handleGetEntity :: Environment -> Page -> Resource ()
-handleGetEntity env page
- = do let lastMod = toClockTime $ pageLastMod page
-
- case pageRevision page of
- 0 -> foundTimeStamp lastMod -- 0 はデフォルトページ
- rev -> foundEntity (strongETag $ show rev) lastMod
+handleGetEntity :: Page -> Resource ()
+handleGetEntity page
+ = do case entityRevision page of
+ 0 -> foundTimeStamp (entityLastMod page) -- 0 はデフォルトページ
+ rev -> foundEntity (strongETag $ show rev) (entityLastMod page)
- setContentType (pageType page)
- setHeader (C8.pack "Content-Disposition")
- (C8.pack $ "attachment; filename=" ++ quoteStr (pageFileName' page))
- outputLBS (pageContent page)
+ setContentType (entityType page)
+ outputLBS (entityContent page)