0 | module HTTP.Prog
 1 |
 2 | import public FS.Posix
 3 | import public HTTP.RequestErr
 4 | import public IO.Async.Logging
 5 | import public IO.Async.Loop.Posix
 6 | import public IO.Async.Posix
 7 | import public IO.Async.Service
 8 |
 9 | %default total
10 |
11 | ||| A server programm runs in the `Async` monad and requires
12 | ||| polling capabilities.
13 | |||
14 | ||| @ es : types of errors a program can fail with
15 | ||| @ a  : result type
16 | public export
17 | 0 HTTPProg : (es : List Type) -> (a : Type) -> Type
18 | HTTPProg = Async Poll
19 |
20 | ||| Logger used in a HTTP server
21 | public export
22 | 0 HTTPLogger : Type
23 | HTTPLogger = Logger Poll
24 |
25 | ||| A `Pull` running in the `Async` monad and requiring
26 | ||| polling capabilities.
27 | |||
28 | ||| @ o  : type of values emitted by the pull
29 | ||| @ es : types of errors a pull can fail with
30 | ||| @ r  : result type
31 | public export
32 | 0 HTTPPull : (o : Type) -> (es : List Type) -> (r : Type) -> Type
33 | HTTPPull = Pull HTTPProg
34 |
35 | ||| A `Stream` running in the `Async` monad and requiring
36 | ||| polling capabilities.
37 | |||
38 | ||| A `Stream` is just an alias for a `Pull` with result type `Unit`.
39 | |||
40 | ||| @ es : types of errors a pull can fail with
41 | ||| @ o  : type of values emitted by the pull
42 | public export
43 | 0 HTTPStream : (es : List Type) -> (o : Type) -> Type
44 | HTTPStream = Stream HTTPProg
45 |
46 | ||| An asynchronous service use to process HTTP requests.
47 | public export
48 | 0 HTTPService : (req : Type) -> (resp : req -> Type) -> Type
49 | HTTPService = Service Poll [RequestErr]
50 |
51 | ||| A handler for error type `e`.
52 | public export
53 | 0 ErrorHandler : (e : Type) -> Type
54 | ErrorHandler e = e -> HTTPProg [] ()
55 |
56 | public export
57 | 0 Handler : Type -> Type
58 | Handler = HTTPProg [RequestErr]
59 |