X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FResource%2FObject.hs;h=b46a86a30a330bbdcdbb412f09def05d66c50d86;hb=522dde5470584bb3f82cb0b4179233724d2408d0;hp=9e30d1eee78d919f8094c10ab02adb886c78b0c4;hpb=790089d18791029ad268b3306ca71f8d5ae44ce1;p=Rakka.git diff --git a/Rakka/Resource/Object.hs b/Rakka/Resource/Object.hs index 9e30d1e..b46a86a 100644 --- a/Rakka/Resource/Object.hs +++ b/Rakka/Resource/Object.hs @@ -1,22 +1,66 @@ +-- -*- Coding: utf-8 -*- module Rakka.Resource.Object ( resObject ) where +import Data.Maybe import Network.HTTP.Lucu +import Network.HTTP.Lucu.Utils import Rakka.Environment +import Rakka.Page +import Rakka.Storage +import Rakka.SystemConfig resObject :: Environment -> ResourceDef resObject env = ResourceDef { resUsesNativeThread = False - , resIsGreedy = False - , resGet = Just $ do setContentType $ read "text/plain" - output "FIXME: not implemented" + , resIsGreedy = True + , resGet = Just $ getPathInfo >>= handleGet env . toPageName , resHead = Nothing , resPost = Nothing , resPut = Nothing , resDelete = Nothing } + where + toPageName :: [String] -> PageName + toPageName = decodePageName . joinWith "/" + + +handleGet :: Environment -> PageName -> Resource () +handleGet env name + = do pageM <- getPage (envStorage env) name Nothing + case pageM of + Nothing -> foundNoEntity Nothing + Just page -> if isEntity page then + handleGetEntity page + else + handleRedirect env page + + +{- + HTTP/1.1 302 Found + Location: http://example.org/object/Destination +-} +handleRedirect :: Environment -> Page -> Resource () +handleRedirect env redir + = do BaseURI baseURI <- getSysConf (envSysConf env) + redirect Found (mkObjectURI baseURI $ redirName redir) + + +{- + HTTP/1.1 200 OK + Content-Type: image/png + + ... +-} +handleGetEntity :: Page -> Resource () +handleGetEntity page + = do case entityRevision page of + 0 -> foundTimeStamp (entityLastMod page) -- 0 はデフォルトページ + rev -> foundEntity (strongETag $ show rev) (entityLastMod page) + setContentType (entityType page) + outputLBS (entityContent page)