X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FResource%2FObject.hs;h=8365381932b7a41fb8460c8c1f1676d1b991a917;hb=88747f2;hp=a18a268cb3504dc55badca12134cdf5883d02ed7;hpb=602cb8599101da778f6cbb043451cfa458dff89c;p=Rakka.git diff --git a/Rakka/Resource/Object.hs b/Rakka/Resource/Object.hs index a18a268..8365381 100644 --- a/Rakka/Resource/Object.hs +++ b/Rakka/Resource/Object.hs @@ -1,17 +1,14 @@ +-- -*- 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.Environment import Rakka.Page import Rakka.Storage import Rakka.SystemConfig -import System.Time +import System.FilePath.Posix resObject :: Environment -> ResourceDef @@ -27,21 +24,18 @@ resObject env } where toPageName :: [String] -> PageName - toPageName = decodePageName . joinWith "/" + toPageName = UTF8.decodeString . joinPath handleGet :: Environment -> PageName -> Resource () 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 {- @@ -60,15 +54,11 @@ handleRedirect env redir ... -} -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)