0 | module HTTP.API.Client.Path
 1 |
 2 | import HTTP.API.Client.Interface
 3 |
 4 | %default total
 5 |
 6 | export
 7 | recTypes : (ps : List Part) -> TList (PartsTypes ps)
 8 | recTypes []                = []
 9 | recTypes (PScheme _ :: xs) = recTypes xs
10 | recTypes (PAuth _   :: xs) = recTypes xs
11 | recTypes (PStr _    :: xs) = recTypes xs
12 | recTypes (PTill _   :: xs) = recTypes xs
13 | recTypes (Capture t :: xs) = t :: recTypes xs
14 |
15 | reqPath :
16 |      (ps : List Part)
17 |   -> All EncodeMany (PartsTypes ps)
18 |   -> HList (PartsTypes ps)
19 |   -> List ByteString
20 | reqPath []        _  _  = []
21 | reqPath (PScheme _ :: ps) es      vs      = reqPath ps es vs
22 | reqPath (PAuth _   :: ps) es      vs      = reqPath ps es vs
23 | reqPath (PStr s    :: ps) es      vs      = fromString s :: reqPath ps es vs
24 | reqPath (PTill s   :: ps) es      vs      = fromString s :: reqPath ps es vs
25 | reqPath (Capture _ :: ps) (e::es) (v::vs) = encodeMany v ++ reqPath ps es vs
26 |
27 | adjAuth : List Part -> HTTPRequest -> HTTPRequest
28 | adjAuth []             r = r
29 | adjAuth (PAuth s :: _) r = adjURI {authority := Just $ cast s} r
30 | adjAuth (_ :: xs)      r = adjAuth xs r
31 |
32 | adjScheme : List Part -> HTTPRequest -> HTTPRequest
33 | adjScheme []               r = r
34 | adjScheme (PScheme s :: _) r = adjURI {scheme := Just $ cast s} r
35 | adjScheme (_ :: xs)        r = adjScheme xs r
36 |
37 | public export
38 | Receive ReqPath where
39 |   RecConstraint p = All EncodeMany (PartsTypes p.parts)
40 |   RecTypes p = PartsTypes p.parts
41 |   recs p = recTypes p.parts
42 |   adjRequest (Path ps) vs r =
43 |     let pth := reqPath ps con vs
44 |      in adjURI {path := pth} . adjScheme ps $ adjAuth ps r
45 |
46 | public export
47 | GetResponse ReqPath where
48 |   RespEncodings _ = []
49 |   RespTypes _ = []
50 |