@@ -7,19 +7,27 @@ module Node.HTTP.HTTPS
7
7
, handshakeTimeout
8
8
, requestCert
9
9
, rejectUnauthorized
10
+ , NPNProtocols (..)
10
11
, npnProtocols
12
+ , ALPNProtocols (..)
11
13
, alpnProtocols
12
14
, sessionTimeout
13
15
, ticketKeys
16
+ , PFX (..)
14
17
, pfx
18
+ , Key (..)
15
19
, key
16
20
, passphrase
21
+ , Cert (..)
17
22
, cert
23
+ , CA (..)
18
24
, ca
25
+ , CRL (..)
19
26
, crl
20
27
, ciphers
21
28
, honorCipherOrder
22
29
, ecdhCurve
30
+ , DHParam (..)
23
31
, dhparam
24
32
, secureProtocol
25
33
, secureOptions
@@ -29,8 +37,10 @@ module Node.HTTP.HTTPS
29
37
import Prelude
30
38
31
39
import Control.Monad.Eff (Eff )
40
+ import Data.ArrayBuffer.Types (Uint8Array )
41
+ import Data.Foreign (Foreign , toForeign )
42
+ import Data.Functor.Contravariant (cmap )
32
43
import Data.Options (Options , Option , options , opt )
33
- import Data.Foreign (Foreign )
34
44
import Node.Buffer (Buffer )
35
45
import Node.HTTP (Request , Response , Server , HTTP )
36
46
@@ -49,17 +59,47 @@ requestCert = opt "requestCert"
49
59
rejectUnauthorized :: Option SSLOptions Boolean
50
60
rejectUnauthorized = opt " rejectUnauthorized"
51
61
52
- -- | The type variable t should be a string[], Buffer[], Uint8Array[], Buffer,
53
- -- | or Uint8Array.
62
+ -- | The npnProtocols option can be a String, a Buffer, a Uint8Array, or an
63
+ -- | array of any of those types.
64
+ data NPNProtocols
65
+ = NPNProtocolsString String
66
+ | NPNProtocolsBuffer Buffer
67
+ | NPNProtocolsUint8Array Uint8Array
68
+ | NPNProtocolsStringArray (Array String )
69
+ | NPNProtocolsBufferArray (Array Buffer )
70
+ | NPNProtocolsUint8ArrayArray (Array Uint8Array )
71
+
54
72
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
55
- npnProtocols :: forall t . Option SSLOptions t
56
- npnProtocols = opt " NPNProtocols"
73
+ npnProtocols :: Option SSLOptions NPNProtocols
74
+ npnProtocols = cmap extract $ opt " NPNProtocols"
75
+ where
76
+ extract (NPNProtocolsString s) = toForeign s
77
+ extract (NPNProtocolsBuffer b) = toForeign b
78
+ extract (NPNProtocolsUint8Array u) = toForeign u
79
+ extract (NPNProtocolsStringArray sa) = toForeign sa
80
+ extract (NPNProtocolsBufferArray ba) = toForeign ba
81
+ extract (NPNProtocolsUint8ArrayArray ua) = toForeign ua
82
+
83
+ -- | The alpnProtocols option can be a String, a Buffer, a Uint8Array, or an
84
+ -- | array of any of those types.
85
+ data ALPNProtocols
86
+ = ALPNProtocolsString String
87
+ | ALPNProtocolsBuffer Buffer
88
+ | ALPNProtocolsUint8Array Uint8Array
89
+ | ALPNProtocolsStringArray (Array String )
90
+ | ALPNProtocolsBufferArray (Array Buffer )
91
+ | ALPNProtocolsUint8ArrayArray (Array Uint8Array )
57
92
58
- -- | The type variable t should be a string[], Buffer[], Uint8Array[], Buffer,
59
- -- | or Uint8Array.
60
93
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
61
- alpnProtocols :: forall t . Option SSLOptions t
62
- alpnProtocols = opt " ALPNProtocols"
94
+ alpnProtocols :: Option SSLOptions ALPNProtocols
95
+ alpnProtocols = cmap extract $ opt " ALPNProtocols"
96
+ where
97
+ extract (ALPNProtocolsString s) = toForeign s
98
+ extract (ALPNProtocolsBuffer b) = toForeign b
99
+ extract (ALPNProtocolsUint8Array u) = toForeign u
100
+ extract (ALPNProtocolsStringArray sa) = toForeign sa
101
+ extract (ALPNProtocolsBufferArray ba) = toForeign ba
102
+ extract (ALPNProtocolsUint8ArrayArray ua) = toForeign ua
63
103
64
104
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
65
105
sessionTimeout :: Option SSLOptions Int
@@ -69,35 +109,87 @@ sessionTimeout = opt "sessionTimeout"
69
109
ticketKeys :: Option SSLOptions Buffer
70
110
ticketKeys = opt " ticketKeys"
71
111
72
- -- | The type variable t should be a string or Buffer.
112
+ -- | The PFX option can take either a String or a Buffer
113
+ data PFX = PFXString String | PFXBuffer Buffer
114
+
73
115
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
74
- pfx :: forall t . Option SSLOptions t
75
- pfx = opt " pfx"
116
+ pfx :: Option SSLOptions PFX
117
+ pfx = cmap extract $ opt " pfx"
118
+ where
119
+ extract (PFXString s) = toForeign s
120
+ extract (PFXBuffer b) = toForeign b
121
+
122
+ -- | The key option can be a String, a Buffer, an array of strings, or an array
123
+ -- | of buffers.
124
+ data Key
125
+ = KeyString String
126
+ | KeyBuffer Buffer
127
+ | KeyStringArray (Array String )
128
+ | KeyBufferArray (Array Buffer )
76
129
77
- -- | The type variable t should be a string, string[], Buffer, Buffer[], or
78
- -- | Object[].
79
130
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
80
- key :: forall t . Option SSLOptions t
81
- key = opt " key"
131
+ key :: Option SSLOptions Key
132
+ key = cmap extract $ opt " key"
133
+ where
134
+ extract (KeyString s) = toForeign s
135
+ extract (KeyBuffer b) = toForeign b
136
+ extract (KeyStringArray sa) = toForeign sa
137
+ extract (KeyBufferArray ba) = toForeign ba
82
138
83
139
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
84
140
passphrase :: Option SSLOptions String
85
141
passphrase = opt " passphrase"
86
142
87
- -- | The type variable t should be a string, string[], Buffer, or Buffer[].
143
+ -- | The cert option can be a String, a Buffer, an array of strings, or an array
144
+ -- | of buffers.
145
+ data Cert
146
+ = CertString String
147
+ | CertBuffer Buffer
148
+ | CertStringArray (Array String )
149
+ | CertBufferArray (Array Buffer )
150
+
88
151
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
89
- cert :: forall t . Option SSLOptions t
90
- cert = opt " cert"
152
+ cert :: Option SSLOptions Cert
153
+ cert = cmap extract $ opt " cert"
154
+ where
155
+ extract (CertString s) = toForeign s
156
+ extract (CertBuffer b) = toForeign b
157
+ extract (CertStringArray sa) = toForeign sa
158
+ extract (CertBufferArray ba) = toForeign ba
159
+
160
+ -- | The CA option can be a String, a Buffer, an array of strings, or an array
161
+ -- | of buffers.
162
+ data CA
163
+ = CAString String
164
+ | CABuffer Buffer
165
+ | CAStringArray (Array String )
166
+ | CABufferArray (Array Buffer )
91
167
92
- -- | The type variable t should be a string, string[], Buffer, or Buffer[].
93
168
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
94
- ca :: forall t . Option SSLOptions t
95
- ca = opt " ca"
169
+ ca :: Option SSLOptions CA
170
+ ca = cmap extract $ opt " ca"
171
+ where
172
+ extract (CAString s) = toForeign s
173
+ extract (CABuffer b) = toForeign b
174
+ extract (CAStringArray sa) = toForeign sa
175
+ extract (CABufferArray ba) = toForeign ba
176
+
177
+ -- | The CRL option can be a String, a Buffer, an array of strings, or an array
178
+ -- | of buffers.
179
+ data CRL
180
+ = CRLString String
181
+ | CRLBuffer Buffer
182
+ | CRLStringArray (Array String )
183
+ | CRLBufferArray (Array Buffer )
96
184
97
- -- | The type variable t should be a string, string[], Buffer, or Buffer[].
98
185
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
99
- crl :: forall t . Option SSLOptions t
100
- crl = opt " crl"
186
+ crl :: Option SSLOptions CRL
187
+ crl = cmap extract $ opt " crl"
188
+ where
189
+ extract (CRLString s) = toForeign s
190
+ extract (CRLBuffer b) = toForeign b
191
+ extract (CRLStringArray sa) = toForeign sa
192
+ extract (CRLBufferArray ba) = toForeign ba
101
193
102
194
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
103
195
ciphers :: Option SSLOptions String
@@ -111,10 +203,15 @@ honorCipherOrder = opt "honorCipherOrder"
111
203
ecdhCurve :: Option SSLOptions String
112
204
ecdhCurve = opt " ecdhCurve"
113
205
114
- -- | The type variable t should be a string or Buffer.
206
+ -- | The DHParam option can take either a String or a Buffer
207
+ data DHParam = DHParamString String | DHParamBuffer Buffer
208
+
115
209
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
116
- dhparam :: forall t . Option SSLOptions t
117
- dhparam = opt " dhparam"
210
+ dhparam :: Option SSLOptions DHParam
211
+ dhparam = cmap extract $ opt " dhparam"
212
+ where
213
+ extract (DHParamString s) = toForeign s
214
+ extract (DHParamBuffer b) = toForeign b
118
215
119
216
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
120
217
secureProtocol :: Option SSLOptions String
@@ -128,6 +225,8 @@ secureOptions = opt "secureOptions"
128
225
sessionIdContext :: Option SSLOptions String
129
226
sessionIdContext = opt " sessionIdContext"
130
227
228
+ -- | Create an HTTPS server, given the SSL options and a function to be executed
229
+ -- | when a request is received.
131
230
foreign import createServerImpl ::
132
231
forall eff .
133
232
Foreign ->
0 commit comments