|
1 | 1 | module Node.Http2.Client |
2 | | - ( ConnectOptions |
3 | | - , connect |
| 2 | + ( connect |
4 | 3 | , connect' |
5 | 4 | ) where |
6 | 5 |
|
7 | 6 | import Effect (Effect) |
8 | 7 | import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2) |
9 | | -import Node.Buffer.Immutable (ImmutableBuffer) |
10 | | -import Node.Http2.Types (Client, Http2Session, Settings, TlsSecureContextOptions) |
11 | | -import Node.Net.Socket (Socket) |
| 8 | +import Node.Http2.Types (Http2ClientConnectOptions, Http2Session) |
| 9 | +import Node.Net.Types (ConnectTcpOptions) |
| 10 | +import Node.TLS.Types (Client, ConnectTlsSocketOptions, CreateSecureContextOptions) |
12 | 11 | import Prim.Row as Row |
13 | | -import Type.Row (type (+)) |
14 | 12 |
|
15 | 13 | connect :: String -> Effect (Http2Session Client) |
16 | 14 | connect authority = runEffectFn1 connectAuthImpl authority |
17 | 15 |
|
18 | 16 | foreign import connectAuthImpl :: EffectFn1 (String) (Http2Session Client) |
19 | 17 |
|
20 | | --- | `maxDeflateDynamicTableSize` <number> Sets the maximum dynamic table size for deflating header fields. Default: 4Kib. |
21 | | --- | `maxSettings` <number> Sets the maximum number of settings entries per SETTINGS frame. The minimum value allowed is 1. Default: 32. |
22 | | --- | `maxSessionMemory`<number> Sets the maximum memory that the Http2Session is permitted to use. The value is expressed in terms of number of megabytes, e.g. 1 equal 1 megabyte. The minimum value allowed is 1. This is a credit based limit, existing Http2Streams may cause this limit to be exceeded, but new Http2Stream instances will be rejected while this limit is exceeded. The current number of Http2Stream sessions, the current memory use of the header compression tables, current data queued to be sent, and unacknowledged PING and SETTINGS frames are all counted towards the current limit. Default: 10. |
23 | | --- | `maxHeaderListPairs` <number> Sets the maximum number of header entries. This is similar to server.maxHeadersCount or request.maxHeadersCount in the node:http module. The minimum value is 1. Default: 128. |
24 | | --- | `maxOutstandingPings` <number> Sets the maximum number of outstanding, unacknowledged pings. Default: 10. |
25 | | --- | `maxReservedRemoteStreams` <number> Sets the maximum number of reserved push streams the client will accept at any given time. Once the current number of currently reserved push streams exceeds reaches this limit, new push streams sent by the server will be automatically rejected. The minimum allowed value is 0. The maximum allowed value is 232-1. A negative value sets this option to the maximum allowed value. Default: 200. |
26 | | --- | `maxSendHeaderBlockLength` <number> Sets the maximum allowed size for a serialized, compressed block of headers. Attempts to send headers that exceed this limit will result in a 'frameError' event being emitted and the stream being closed and destroyed. |
27 | | --- | `paddingStrategy` <number> Strategy used for determining the amount of padding to use for HEADERS and DATA frames. Default: http2.constants.PADDING_STRATEGY_NONE. Value may be one of: |
28 | | --- | `peerMaxConcurrentStreams` <number> Sets the maximum number of concurrent streams for the remote peer as if a SETTINGS frame had been received. Will be overridden if the remote peer sets its own value for maxConcurrentStreams. Default: 100. |
29 | | --- | `protocol` <string> The protocol to connect with, if not set in the authority. Value may be either 'http:' or 'https:'. Default: 'https:' |
30 | | --- | `settings` <HTTP/2 Settings Object> The initial settings to send to the remote peer upon connection. |
31 | | --- | `createConnection` <Function> An optional callback that receives the URL instance passed to connect and the options object, and returns any Duplex stream that is to be used as the connection for this session. |
32 | | --- | `unknownProtocolTimeout` <number> Specifies a timeout in milliseconds that a server should wait when an 'unknownProtocol' event is emitted. If the socket has not been destroyed by that time the server will destroy it. Default: 10000. |
33 | | --- | |
34 | | --- | Note: `createConnection` is not supported for now. |
35 | | -type ConnectOptions :: (Type -> Type) -> Row Type -> Row Type |
36 | | -type ConnectOptions f r = |
37 | | - ( maxDeflateDynamicTableSize :: f Int |
38 | | - , maxSettings :: f Int |
39 | | - , maxSessionMemory :: f Int |
40 | | - , maxHeaderListPairs :: f Int |
41 | | - , maxOutstandingPings :: f Int |
42 | | - , maxReservedRemoteStreams :: f Int |
43 | | - , maxSendHeaderBlockLength :: f Int |
44 | | - , paddingStrategy :: f Int |
45 | | - , peerMaxConcurrentStreams :: f Int |
46 | | - , protocol :: f String |
47 | | - , settings :: f Settings |
48 | | - -- , createConnection :: Function -- not supported for now. |
49 | | - , unknownProtocolTimeout :: f Int |
50 | | - | r |
51 | | - ) |
52 | | - |
53 | | -type TlsConnectOptions :: (Type -> Type) -> Row Type -> Row Type |
54 | | -type TlsConnectOptions f r = |
55 | | - ( enableTrace :: f Boolean |
56 | | - , socket :: f Socket |
57 | | - , allowHalfOpen :: f Boolean |
58 | | - , rejectUnauthorized :: f Boolean |
59 | | - -- , pskCallback :: <Function |
60 | | - , "ALPNProtocols" :: f (Array ImmutableBuffer) |
61 | | - , servername :: f String |
62 | | - -- , checkServerIdentity :: EffectFn2 String ? (Nullable Error) -- ignoring for now |
63 | | - , session :: f ImmutableBuffer |
64 | | - , minDHSize :: f Int |
65 | | - , highWaterMark :: f Int |
66 | | - -- , secureContext :: f TlsSecureContext -- ignoring for now |
67 | | - -- , onread :: <Object> -- ignoring |
68 | | - | r |
69 | | - ) |
70 | | - |
71 | | -type TcpConnectOptions :: (Type -> Type) -> Row Type -> Row Type |
72 | | -type TcpConnectOptions f r = |
73 | | - ( port :: f Int |
74 | | - , host :: f String |
75 | | - , localAddress :: f String |
76 | | - , localPort :: f Int |
77 | | - , family :: f Int |
78 | | - -- , hints :: f number |
79 | | - -- , lookup :: f Function |
80 | | - , noDelay :: f Boolean |
81 | | - , keepAlive :: f Boolean |
82 | | - , keepAliveInitialDelay :: f Number -- is this milliseconds or seconds? |
83 | | - -- , autoSelectFamily :: f Boolean |
84 | | - -- , autoSelectFamilyAttemptTimeout :: f number |
85 | | - | r |
86 | | - ) |
87 | | - |
88 | 18 | connect' |
89 | 19 | :: forall rec trash |
90 | | - . Row.Union rec trash (ConnectOptions Unlift + TlsConnectOptions Unlift + TlsSecureContextOptions Unlift + TcpConnectOptions Unlift + ()) |
| 20 | + . Row.Union rec trash (Http2ClientConnectOptions (ConnectTlsSocketOptions Client (CreateSecureContextOptions (ConnectTcpOptions ())))) |
91 | 21 | => String |
92 | 22 | -> { | rec } |
93 | 23 | -> Effect (Http2Session Client) |
94 | 24 | connect' authority rec = runEffectFn2 connectAuthOptionsImpl authority rec |
95 | 25 |
|
96 | 26 | foreign import connectAuthOptionsImpl :: forall r. EffectFn2 (String) ({ | r }) (Http2Session Client) |
97 | 27 |
|
98 | | -type Unlift :: Type -> Type |
99 | | -type Unlift a = a |
100 | | - |
101 | | -foreign import undefined :: forall a. a |
0 commit comments