0 | module HTTP.API.Server.Path
2 | import HTTP.API.Server.Interface
6 | parameters {auto loc : HTTPLocal}
9 | -> All DecodeMany (PartsTypes ps)
12 | canHandlePath [] [] [] = True
13 | canHandlePath (PStr s :: ys) xs (p :: ps) =
14 | s == toString p && canHandlePath ys xs ps
15 | canHandlePath (PTill s :: ys) xs (p :: ps) =
17 | then canHandlePath ys xs ps
18 | else canHandlePath (PTill s :: ys) xs ps
19 | canHandlePath (Capture t :: ys) (x::xs) ps =
20 | case simulateDecode @{x} ps of
21 | Just ps2 => canHandlePath ys xs ps2
23 | canHandlePath _ _ _ = False
27 | -> All DecodeMany (PartsTypes ps)
29 | -> Either DecodeErr (HList $
PartsTypes ps)
30 | convertRequest [] [] [] = Right []
31 | convertRequest (PStr s :: ys) as (b::bs) = convertRequest ys as bs
32 | convertRequest (PTill s :: ys) as (b::bs) =
34 | then convertRequest ys as bs
35 | else convertRequest (PTill s :: ys) as bs
36 | convertRequest (Capture t :: ys) (a::as) bs = Prelude.do
37 | (bs2,v) <- decodeMany @{a} bs
38 | vs <- convertRequest ys as bs2
40 | convertRequest _ _ _ = Left $
Msg endOfURIPath
44 | InTypes m = PartsTypes m.parts
46 | Constraint m = All DecodeMany (PartsTypes m.parts)
48 | canHandle m r = canHandlePath m.parts con r.uri.path
49 | adjResponse m _ _ = pure
52 | (throw . decodeErr badRequest400)
54 | (convertRequest m.parts con r.uri.path)