X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource%2FTree.hs;h=4a652a7b7aec8ac210f274a8393080ac0fa4ba66;hp=9434cfbbe9f9cbd7e7ad3dbb4a4e2f1cf2f150d8;hb=1ead053df6a792edafa9d714c4c038a8a9c3ad16;hpb=545053db37e71ed18ca59c12467a8ecb10bf5f83 diff --git a/Network/HTTP/Lucu/Resource/Tree.hs b/Network/HTTP/Lucu/Resource/Tree.hs index 9434cfb..4a652a7 100644 --- a/Network/HTTP/Lucu/Resource/Tree.hs +++ b/Network/HTTP/Lucu/Resource/Tree.hs @@ -37,13 +37,13 @@ import Prelude.Unicode -- httpd first searches for a resource in the tree, and then calls -- fallback handlers to ask them for a resource. If all of the -- handlers returned 'Nothing', the httpd responds with 404 Not Found. -type FallbackHandler = [ByteString] → IO (Maybe ResourceDef) +type FallbackHandler = [ByteString] → IO (Maybe Resource) -- |'ResTree' is an opaque structure which is a map from resource path --- to 'ResourceDef'. +-- to 'Resource'. newtype ResTree = ResTree ResNode -- root だから Map ではない type ResSubtree = Map ByteString ResNode -data ResNode = ResNode (Maybe ResourceDef) ResSubtree +data ResNode = ResNode (Maybe Resource) ResSubtree -- |'mkResTree' converts a list of @(path, def)@ to a 'ResTree' e.g. -- @@ -58,13 +58,13 @@ data ResNode = ResNode (Maybe ResourceDef) ResSubtree -- has no involvement in character encodings such as UTF-8, since RFC -- 2616 (HTTP/1.1) says nothing about character encodings to be used -- in \"http\" and \"https\" URI schemas. -mkResTree ∷ [ ([ByteString], ResourceDef) ] → ResTree +mkResTree ∷ [ ([ByteString], Resource) ] → ResTree mkResTree = processRoot ∘ map (first canonicalisePath) where canonicalisePath ∷ [ByteString] → [ByteString] canonicalisePath = filter ((¬) ∘ BS.null) - processRoot ∷ [ ([ByteString], ResourceDef) ] → ResTree + processRoot ∷ [ ([ByteString], Resource) ] → ResTree processRoot list = let (roots, nonRoots) = partition (\(path, _) → null path) list children = processNonRoot nonRoots @@ -79,7 +79,7 @@ mkResTree = processRoot ∘ map (first canonicalisePath) in ResTree (ResNode (Just def) children) - processNonRoot ∷ [ ([ByteString], ResourceDef) ] → ResSubtree + processNonRoot ∷ [ ([ByteString], Resource) ] → ResSubtree processNonRoot list = let subtree = M.fromList [(name, node name) | name ← childNames] @@ -102,7 +102,7 @@ mkResTree = processRoot ∘ map (first canonicalisePath) findResource ∷ ResTree → [FallbackHandler] → URI - → IO (Maybe ([ByteString], ResourceDef)) + → IO (Maybe ([ByteString], Resource)) findResource (ResTree (ResNode rootDefM subtree)) fbs uri = do let path = splitPathInfo uri hasGreedyRoot = maybe False resIsGreedy rootDefM @@ -119,7 +119,7 @@ findResource (ResTree (ResNode rootDefM subtree)) fbs uri walkTree ∷ ResSubtree → [ByteString] → Seq ByteString - → Maybe ([ByteString], ResourceDef) + → Maybe ([ByteString], Resource) walkTree _ [] _ = error "Internal error: should not reach here." @@ -132,14 +132,14 @@ findResource (ResTree (ResNode rootDefM subtree)) fbs uri walkTree tree (x:xs) soFar = do ResNode defM sub ← M.lookup x tree case defM of - Just (ResourceDef { resIsGreedy = True }) + Just (Resource { resIsGreedy = True }) → do def ← defM return (toList $ soFar ⊳ x, def) _ → walkTree sub xs (soFar ⊳ x) fallback ∷ [ByteString] → [FallbackHandler] - → IO (Maybe ([ByteString], ResourceDef)) + → IO (Maybe ([ByteString], Resource)) fallback _ [] = return Nothing fallback path (x:xs) = do m ← x path case m of