1 module Rakka.Resource.Object
6 import Network.HTTP.Lucu
7 import Network.HTTP.Lucu.Utils
8 import Rakka.Environment
11 import Rakka.SystemConfig
12 import System.FilePath
16 resObject :: Environment -> ResourceDef
19 resUsesNativeThread = False
21 , resGet = Just $ getPathInfo >>= handleGet env . toPageName
28 toPageName :: [String] -> PageName
29 toPageName = decodePageName . dropExtension . joinWith "/"
32 handleGet :: Environment -> PageName -> Resource ()
34 = do pageM <- getPage (envStorage env) name
37 -> foundNoEntity Nothing
39 Just redir@(Redirection _ _ _ _)
40 -> handleRedirect env redir
42 Just entity@(Entity _ _ _ _ _ _ _ _ _ _ _ _)
43 -> handleGetEntity env entity
48 Location: http://example.org/object/Destination
50 handleRedirect :: Environment -> Page -> Resource ()
51 handleRedirect env redir
52 = do BaseURI baseURI <- getSysConf (envSysConf env) (BaseURI undefined)
53 redirect Found (mkObjectURI baseURI $ redirName redir)
58 Content-Type: image/png
62 handleGetEntity :: Environment -> Page -> Resource ()
63 handleGetEntity env page
64 = do let lastMod = toClockTime $ pageLastMod page
66 case pageRevision page of
67 Nothing -> foundTimeStamp lastMod
68 Just rev -> foundEntity (strongETag $ show rev) lastMod
70 setContentType (pageType page)
71 outputLBS (pageContent page)