1 module Rakka.Resource.Object
6 import Data.ByteString.Char8 as C8
8 import Network.HTTP.Lucu
9 import Network.HTTP.Lucu.Utils
10 import Rakka.Environment
13 import Rakka.SystemConfig
17 resObject :: Environment -> ResourceDef
20 resUsesNativeThread = False
22 , resGet = Just $ getPathInfo >>= handleGet env . toPageName
29 toPageName :: [String] -> PageName
30 toPageName = decodePageName . joinWith "/"
33 handleGet :: Environment -> PageName -> Resource ()
35 = do pageM <- getPage (envStorage env) name Nothing
38 -> foundNoEntity Nothing
40 Just redir@(Redirection _ _ _ _)
41 -> handleRedirect env redir
43 Just entity@(Entity _ _ _ _ _ _ _ _ _ _ _ _ _ _)
44 -> handleGetEntity env entity
49 Location: http://example.org/object/Destination
51 handleRedirect :: Environment -> Page -> Resource ()
52 handleRedirect env redir
53 = do BaseURI baseURI <- getSysConf (envSysConf env)
54 redirect Found (mkObjectURI baseURI $ redirName redir)
59 Content-Type: image/png
63 handleGetEntity :: Environment -> Page -> Resource ()
64 handleGetEntity env page
65 = do let lastMod = toClockTime $ pageLastMod page
67 case pageRevision page of
68 0 -> foundTimeStamp lastMod -- 0 はデフォルトページ
69 rev -> foundEntity (strongETag $ show rev) lastMod
71 setContentType (pageType page)
72 setHeader (C8.pack "Content-Disposition")
73 (C8.pack $ "attachment; filename=" ++ quoteStr (pageFileName' page))
74 outputLBS (pageContent page)