0 | module HTTP.Request
 1 |
 2 | import Control.Monad.MErr
 3 | import HTTP.API
 4 | import Text.ILex
 5 |
 6 | %default total
 7 |
 8 | ||| A request sent from the client listing the SCGI headers provided by
 9 | ||| the proxy server, the total content size, and an IO action for
10 | ||| streaming the content.
11 | public export
12 | record Request where
13 |   [noHints]
14 |   constructor RQ
15 |
16 |   ||| The HTTP method used for the request
17 |   method      : Method
18 |
19 |   ||| The SCGI headers as sent by the proxy server
20 |   headers     : Headers
21 |
22 |   ||| URI of the request
23 |   uri         : URI
24 |
25 |   ||| Content
26 |   content     : ByteString
27 |
28 | parameters {auto merr : MErr f}
29 |            {auto has  : Has RequestErr es}
30 |
31 |   export
32 |   requestMethod : ByteString -> f es Method
33 |   requestMethod bs =
34 |     case toString bs of
35 |       "GET"    => pure GET
36 |       "HEAD"   => pure HEAD
37 |       "POST"   => pure POST
38 |       "PUT"    => pure PUT
39 |       "DELETE" => pure DELETE
40 |       "PATCH"  => pure PATCH
41 |       s        => throw $ requestErrMsg "Unknown HTTP method: \{s}" badRequest400
42 |
43 |
44 |   export
45 |   requestURI : ByteString -> f es URI
46 |   requestURI bs =
47 |     case parseURI Virtual bs of
48 |       Left  x => throw $ requestErrDetails x badRequest400
49 |       Right u => pure u
50 |