Skip to content

Commit b9879c6

Browse files
Inline Http2 into other modules; small reorg
1 parent b59e295 commit b9879c6

File tree

9 files changed

+455
-388
lines changed

9 files changed

+455
-388
lines changed

src/Node/Http2.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Node/Http2.purs

Lines changed: 0 additions & 365 deletions
This file was deleted.

src/Node/Http2/Client.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import http2 from "node:http2";
2+
3+
export const connectAuthImpl = (auth) => http2.connect(auth);
4+
export const connectAuthOptionsImpl = (auth) => http2.connect(auth, options);
5+
6+
const undefined_ = undefined;
7+
export { undefined_ as undefined }

src/Node/Http2/Client.purs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
module Node.Http2.Client
2+
( ConnectOptions
3+
, connect
4+
, connect'
5+
) where
6+
7+
import Data.Maybe (Maybe(..), fromMaybe)
8+
import Effect (Effect)
9+
import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2)
10+
import Node.Http2.Types (Client, Http2Session, Settings)
11+
import Type.Row (type (+))
12+
13+
connect :: String -> Effect (Http2Session Client)
14+
connect authority = runEffectFn1 connectAuthImpl authority
15+
16+
foreign import connectAuthImpl :: EffectFn1 (String) (Http2Session Client)
17+
18+
-- | `maxDeflateDynamicTableSize` <number> Sets the maximum dynamic table size for deflating header fields. Default: 4Kib.
19+
-- | `maxSettings` <number> Sets the maximum number of settings entries per SETTINGS frame. The minimum value allowed is 1. Default: 32.
20+
-- | `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.
21+
-- | `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.
22+
-- | `maxOutstandingPings` <number> Sets the maximum number of outstanding, unacknowledged pings. Default: 10.
23+
-- | `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.
24+
-- | `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.
25+
-- | `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:
26+
-- | `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.
27+
-- | `protocol` <string> The protocol to connect with, if not set in the authority. Value may be either 'http:' or 'https:'. Default: 'https:'
28+
-- | `settings` <HTTP/2 Settings Object> The initial settings to send to the remote peer upon connection.
29+
-- | `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.
30+
-- | `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.
31+
-- |
32+
-- | Note: `createConnection` is not supported for now.
33+
type ConnectOptions :: (Type -> Type) -> Row Type -> Row Type
34+
type ConnectOptions f r =
35+
( maxDeflateDynamicTableSize :: f Int
36+
, maxSettings :: f Int
37+
, maxSessionMemory :: f Int
38+
, maxHeaderListPairs :: f Int
39+
, maxOutstandingPings :: f Int
40+
, maxReservedRemoteStreams :: f Int
41+
, maxSendHeaderBlockLength :: f Int
42+
, paddingStrategy :: f Int
43+
, peerMaxConcurrentStreams :: f Int
44+
, protocol :: f String
45+
, settings :: f Settings
46+
-- , createConnection :: Function -- not supported for now.
47+
, unknownProtocolTimeout :: f Int
48+
| r
49+
)
50+
51+
connect'
52+
:: String
53+
-> ({ | ConnectOptions Maybe + () } -> { | ConnectOptions Maybe + () })
54+
-> Effect (Http2Session Client)
55+
connect' authority buildOptions = do
56+
let
57+
o = buildOptions
58+
{ maxDeflateDynamicTableSize: Nothing
59+
, maxSettings: Nothing
60+
, maxSessionMemory: Nothing
61+
, maxHeaderListPairs: Nothing
62+
, maxOutstandingPings: Nothing
63+
, maxReservedRemoteStreams: Nothing
64+
, maxSendHeaderBlockLength: Nothing
65+
, paddingStrategy: Nothing
66+
, peerMaxConcurrentStreams: Nothing
67+
, protocol: Nothing
68+
, settings: Nothing
69+
, unknownProtocolTimeout: Nothing
70+
}
71+
72+
finalOptions :: { | ConnectOptions Unlift () }
73+
finalOptions =
74+
{ maxDeflateDynamicTableSize: fromMaybe undefined o.maxDeflateDynamicTableSize
75+
, maxSettings: fromMaybe undefined o.maxSettings
76+
, maxSessionMemory: fromMaybe undefined o.maxSessionMemory
77+
, maxHeaderListPairs: fromMaybe undefined o.maxHeaderListPairs
78+
, maxOutstandingPings: fromMaybe undefined o.maxOutstandingPings
79+
, maxReservedRemoteStreams: fromMaybe undefined o.maxReservedRemoteStreams
80+
, maxSendHeaderBlockLength: fromMaybe undefined o.maxSendHeaderBlockLength
81+
, paddingStrategy: fromMaybe undefined o.paddingStrategy
82+
, peerMaxConcurrentStreams: fromMaybe undefined o.peerMaxConcurrentStreams
83+
, protocol: fromMaybe undefined o.protocol
84+
, settings: fromMaybe undefined o.settings
85+
, unknownProtocolTimeout: fromMaybe undefined o.unknownProtocolTimeout
86+
}
87+
88+
runEffectFn2 connectAuthOptionsImpl authority finalOptions
89+
90+
foreign import connectAuthOptionsImpl :: EffectFn2 (String) ({ | ConnectOptions Unlift + () }) (Http2Session Client)
91+
92+
type Unlift :: Type -> Type
93+
type Unlift a = a
94+
95+
foreign import undefined :: forall a. a

src/Node/Http2/Server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import http2 from "node:http2";
2+
3+
export const createSecureServerImpl = (opts) => http2.createSecureServer(opts);
4+
export const listenImpl = (s, o) => s.listen(o);
5+
6+
const undefined_ = undefined;
7+
export { undefined_ as undefined }
8+
19
export const onCheckContinueImpl = (s, cb) => s.on("checkContinue", cb);
210
export const onConnectionImpl = (s, cb) => s.on("connection", cb);
311
export const onRequestImpl = (s, cb) => s.on("request", cb);

0 commit comments

Comments
 (0)