X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FResource%2FObject.hs;h=8365381932b7a41fb8460c8c1f1676d1b991a917;hb=88747f2463963ff2895a597b3054b12b2288530e;hp=9e30d1eee78d919f8094c10ab02adb886c78b0c4;hpb=790089d18791029ad268b3306ca71f8d5ae44ce1;p=Rakka.git diff --git a/Rakka/Resource/Object.hs b/Rakka/Resource/Object.hs index 9e30d1e..8365381 100644 --- a/Rakka/Resource/Object.hs +++ b/Rakka/Resource/Object.hs @@ -1,22 +1,64 @@ +-- -*- Coding: utf-8 -*- module Rakka.Resource.Object ( resObject ) where - import Network.HTTP.Lucu import Rakka.Environment +import Rakka.Page +import Rakka.Storage +import Rakka.SystemConfig +import System.FilePath.Posix 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 = UTF8.decodeString . joinPath + + +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)