-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.purs
79 lines (60 loc) · 2.97 KB
/
Server.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
module Node.Http2.Server
( toTlsServer
, createSecureServer
, checkContinueH
, requestH
, sessionH
, sessionErrorH
, streamH
, timeoutH
, unknownProtocolH
, setTimeout
, timeout
, updateSettings
) where
import Prelude
import Data.Time.Duration (Milliseconds)
import Effect (Effect)
import Effect.Exception (Error)
import Effect.Uncurried (EffectFn1, EffectFn2, mkEffectFn1, mkEffectFn2, mkEffectFn4, runEffectFn1, runEffectFn2)
import Node.EventEmitter (EventHandle(..))
import Node.EventEmitter.UtilTypes (EventHandle1, EventHandle2, EventHandle4, EventHandle0)
import Node.Http2.Flags (BitwiseFlag)
import Node.Http2.Types (Headers, Http2CreateSecureServerOptions, Http2SecureServer, Http2ServerRequest, Http2ServerResponse, Http2Session, Http2Stream, Settings)
import Node.Net.Types (NewServerOptions)
import Node.Stream (Duplex)
import Node.TLS.Types (CreateSecureContextOptions, Server, TlsCreateServerOptions, TlsServer)
import Prim.Row as Row
import Unsafe.Coerce (unsafeCoerce)
toTlsServer :: Http2SecureServer -> TlsServer
toTlsServer = unsafeCoerce
createSecureServer
:: forall rec trash
. Row.Union rec trash (Http2CreateSecureServerOptions (TlsCreateServerOptions Server (CreateSecureContextOptions (NewServerOptions ()))))
=> { | rec }
-> Effect Http2SecureServer
createSecureServer options = runEffectFn1 createSecureServerImpl options
foreign import createSecureServerImpl :: forall r. EffectFn1 { | r } (Http2SecureServer)
checkContinueH :: EventHandle2 Http2SecureServer Http2ServerRequest Http2ServerResponse
checkContinueH = EventHandle "checkContinue" \cb -> mkEffectFn2 \a b -> cb a b
requestH :: EventHandle2 Http2SecureServer Http2ServerRequest Http2ServerResponse
requestH = EventHandle "request" \cb -> mkEffectFn2 \a b -> cb a b
sessionH :: EventHandle1 Http2SecureServer (Http2Session Server)
sessionH = EventHandle "session" mkEffectFn1
sessionErrorH :: EventHandle2 Http2SecureServer Error (Http2Session Server)
sessionErrorH = EventHandle "sessionError" \cb -> mkEffectFn2 \a b -> cb a b
streamH :: EventHandle4 Http2SecureServer (Http2Stream Server) (Headers) BitwiseFlag (Array String)
streamH = EventHandle "stream" \cb -> mkEffectFn4 \a b c d -> cb a b c d
timeoutH :: EventHandle0 TlsServer
timeoutH = EventHandle "timeout" identity
unknownProtocolH :: EventHandle1 Http2SecureServer Duplex
unknownProtocolH = EventHandle "unknownProtocol" mkEffectFn1
setTimeout :: Http2SecureServer -> Milliseconds -> Effect Http2SecureServer
setTimeout s ms = runEffectFn2 setTimeoutImpl s ms
foreign import setTimeoutImpl :: EffectFn2 (Http2SecureServer) (Milliseconds) (Http2SecureServer)
timeout :: Http2SecureServer -> Effect Milliseconds
timeout s = runEffectFn1 timeoutImpl s
foreign import timeoutImpl :: EffectFn1 (Http2SecureServer) (Milliseconds)
updateSettings :: Http2SecureServer -> Settings -> Effect Unit
updateSettings s set = runEffectFn2 updateSettingsImpl s set
foreign import updateSettingsImpl :: EffectFn2 (Http2SecureServer) (Settings) (Unit)