0 | module Node.HTTP2.ClientHttp2Session
 1 |
 2 | import Node.Error
 3 | import Node.Event.Internal
 4 | import Node.HTTP2.ClientHttp2Stream
 5 | import Node.HTTP2.Headers
 6 |
 7 | export
 8 | data ClientHttp2Session : Type where [external]
 9 |
10 | %foreign """
11 |   node:lambda:
12 |   (session, method, path, headers) =>
13 |     session.request({
14 |       ...headers,
15 |       ':method': method,
16 |       ':path': path
17 |     })
18 |   """
19 | ffi_request : ClientHttp2Session -> String -> String -> Headers -> PrimIO ClientHttp2Stream
20 |
21 | export
22 | (.get) : HasIO io => ClientHttp2Session -> String -> Headers -> io ClientHttp2Stream
23 | (.get) session path headers = primIO $ ffi_request session "GET" path headers
24 |
25 | export
26 | (.post) : HasIO io => ClientHttp2Session -> String -> Headers -> io ClientHttp2Stream
27 | (.post) session path headers = primIO $ ffi_request session "POST" path headers
28 |
29 | %foreign "node:lambda: (session) => session.close()"
30 | ffi_close : ClientHttp2Session -> PrimIO ()
31 |
32 | export
33 | (.close) : HasIO io => ClientHttp2Session -> io ()
34 | (.close) session = primIO $ ffi_close session
35 |
36 | %foreign nodeOn2 "stream"
37 | ffi_onStream : a -> (b -> c -> PrimIO ()) -> PrimIO ()
38 |
39 | export
40 | (.onStream) : HasIO io => ClientHttp2Session -> (ClientHttp2Stream -> Headers -> IO ()) -> io ()
41 | (.onStream) = on2 ffi_onStream
42 |
43 | %foreign nodeOn1 "error"
44 | ffi_onError : a -> (b -> PrimIO ()) -> PrimIO ()
45 |
46 | export
47 | (.onError) : HasIO io => ClientHttp2Session -> (Error -> IO ()) -> io ()
48 | (.onError) = on1 ffi_onError
49 |
50 |