@@ -41,7 +41,6 @@ module Node.HTTP2.Client
4141 , request
4242 , onceErrorSession
4343 , onceResponse
44- , onStream
4544 , onceStream
4645 , onceHeaders
4746 , closeSession
@@ -64,6 +63,7 @@ import Effect (Effect)
6463import Effect.Exception (Error )
6564import Node.Buffer (Buffer )
6665import Node.HTTP2 (Flags , HeadersObject , OptionsObject )
66+ import Node.HTTP2.Internal (Http2Session , Http2Stream )
6767import Node.HTTP2.Internal as Internal
6868import Node.Net.Socket (Socket )
6969import Node.Stream (Duplex )
@@ -75,6 +75,9 @@ import Unsafe.Coerce (unsafeCoerce)
7575-- | See [__Class: ClientHttp2Session__](https://nodejs.org/docs/latest/api/http2.html#class-clienthttp2session)
7676foreign import data ClientHttp2Session :: Type
7777
78+ upcastClientHttp2Session :: ClientHttp2Session -> Http2Session
79+ upcastClientHttp2Session = unsafeCoerce
80+
7881-- | https://nodejs.org/docs/latest/api/http2.html#http2connectauthority-options-listener
7982foreign import connect :: URL -> OptionsObject -> (ClientHttp2Session -> Socket -> Effect Unit ) -> Effect ClientHttp2Session
8083
@@ -89,6 +92,9 @@ foreign import onceReady :: Socket -> (Effect Unit) -> Effect (Effect Unit)
8992-- | See [__Class: ClientHttp2Stream__](https://nodejs.org/docs/latest/api/http2.html#class-clienthttp2stream)
9093foreign import data ClientHttp2Stream :: Type
9194
95+ upcastClientHttp2Stream :: ClientHttp2Stream -> Http2Stream
96+ upcastClientHttp2Stream = unsafeCoerce
97+
9298-- |https://nodejs.org/docs/latest/api/http2.html#clienthttp2sessionrequestheaders-options
9399foreign import request :: ClientHttp2Session -> HeadersObject -> OptionsObject -> Effect ClientHttp2Stream
94100
@@ -97,19 +103,19 @@ foreign import destroy :: ClientHttp2Stream -> Effect Unit
97103
98104-- | https://nodejs.org/docs/latest/api/http2.html#http2sessionclosecallback
99105closeSession :: ClientHttp2Session -> Effect Unit -> Effect Unit
100- closeSession http2session = Internal .closeSession (unsafeCoerce http2session)
106+ closeSession http2session = Internal .closeSession (upcastClientHttp2Session http2session)
101107
102108-- | https://nodejs.org/docs/latest/api/http2.html#event-response
103109-- |
104- -- | Listen for one event, then remove the event listener.
110+ -- | Listen for one event, call the callback, then remove the event listener.
105111-- |
106112-- | Returns an effect for removing the event listener before the event
107113-- | is raised.
108114foreign import onceResponse :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effect Unit ) -> Effect (Effect Unit )
109115
110116-- | https://nodejs.org/docs/latest/api/http2.html#event-headers
111117-- |
112- -- | Listen for one event, then remove the event listener.
118+ -- | Listen for one event, call the callback, then remove the event listener.
113119-- |
114120-- | Returns an effect for removing the event listener before the event
115121-- | is raised.
@@ -119,38 +125,31 @@ foreign import onceHeaders :: ClientHttp2Stream -> (HeadersObject -> Flags -> Ef
119125-- |
120126-- | https://nodejs.org/docs/latest/api/http2.html#push-streams-on-the-client
121127-- |
122- -- | Listen for one event, then remove the event listener.
128+ -- | Listen for one event, call the callback, then remove the event listener.
123129-- |
124130-- | Returns an effect for removing the event listener before the event
125- -- | is raised.
126- onceStream :: ClientHttp2Session -> (ClientHttp2Stream -> HeadersObject -> Flags -> Effect Unit ) -> Effect (Effect Unit )
127- onceStream http2session callback = Internal .onceStream (unsafeCoerce http2session) (\http2stream -> callback (unsafeCoerce http2stream))
128-
129- -- | https://nodejs.org/docs/latest/api/http2.html#event-stream
130131-- |
131- -- | https://nodejs.org/docs/latest/api/http2.html#push-streams-on-the-client
132- -- |
133- -- | Returns an effect for removing the event listener.
134- onStream :: ClientHttp2Session -> (ClientHttp2Stream -> HeadersObject -> Flags -> Effect Unit ) -> Effect (Effect Unit )
135- onStream http2session callback = Internal .onStream (unsafeCoerce http2session) (\http2stream -> callback (unsafeCoerce http2stream))
132+ -- | https://nodejs.org/docs/latest/api/http2.html#event-stream
133+ -- | is raised.
134+ foreign import onceStream :: ClientHttp2Session -> (ClientHttp2Stream -> HeadersObject -> Flags -> Effect Unit ) -> Effect (Effect Unit )
136135
137136-- | https://nodejs.org/docs/latest/api/http2.html#event-error
138137-- |
139- -- | Listen for one event, then remove the event listener.
138+ -- | Listen for one event, call the callback, then remove the event listener.
140139-- |
141140-- | Returns an effect for removing the event listener before the event
142141-- | is raised.
143142onceErrorSession :: ClientHttp2Session -> (Error -> Effect Unit ) -> Effect (Effect Unit )
144- onceErrorSession http2session = Internal .onceEmitterError (unsafeCoerce http2session)
143+ onceErrorSession http2session = Internal .onceSessionEmitterError (upcastClientHttp2Session http2session)
145144
146145-- | https://nodejs.org/docs/latest/api/http2.html#event-error_1
147146-- |
148- -- | Listen for one event, then remove the event listener.
147+ -- | Listen for one event, call the callback, then remove the event listener.
149148-- |
150149-- | Returns an effect for removing the event listener before the event
151150-- | is raised.
152151onceErrorStream :: ClientHttp2Stream -> (Error -> Effect Unit ) -> Effect (Effect Unit )
153- onceErrorStream http2stream = Internal .onceEmitterError (unsafeCoerce http2stream)
152+ onceErrorStream http2stream = Internal .onceStreamEmitterError (upcastClientHttp2Stream http2stream)
154153
155154-- | https://nodejs.org/docs/latest/api/http2.html#event-push
156155-- |
@@ -159,46 +158,46 @@ foreign import oncePush :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effec
159158
160159-- | https://nodejs.org/docs/latest/api/http2.html#event-trailers
161160-- |
162- -- | Listen for one event, then remove the event listener.
161+ -- | Listen for one event, call the callback, then remove the event listener.
163162-- |
164163-- | Returns an effect for removing the event listener before the event
165164-- | is raised.
166165onceTrailers :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effect Unit ) -> Effect (Effect Unit )
167- onceTrailers http2stream = Internal .onceTrailers (unsafeCoerce http2stream)
166+ onceTrailers http2stream = Internal .onceTrailers (upcastClientHttp2Stream http2stream)
168167
169168-- | https://nodejs.org/docs/latest/api/http2.html#event-wanttrailers
170169-- |
171- -- | Listen for one event, then remove the event listener.
170+ -- | Listen for one event, call the callback, then remove the event listener.
172171-- |
173172-- | Returns an effect for removing the event listener before the event
174173-- | is raised.
175174onceWantTrailers :: ClientHttp2Stream -> Effect Unit -> Effect (Effect Unit )
176- onceWantTrailers http2stream = Internal .onceWantTrailers (unsafeCoerce http2stream)
175+ onceWantTrailers http2stream = Internal .onceWantTrailers (upcastClientHttp2Stream http2stream)
177176
178177-- | https://nodejs.org/docs/latest/api/http2.html#http2streamsendtrailersheaders
179178-- |
180179-- | > When sending a request or sending a response, the `options.waitForTrailers` option must be set in order to keep the `Http2Stream` open after the final `DATA` frame so that trailers can be sent.
181180sendTrailers :: ClientHttp2Stream -> HeadersObject -> Effect Unit
182- sendTrailers http2stream = Internal .sendTrailers (unsafeCoerce http2stream)
181+ sendTrailers http2stream = Internal .sendTrailers (upcastClientHttp2Stream http2stream)
183182
184183-- | https://nodejs.org/docs/latest/api/stream.html#event-data
185184-- |
186185-- | Returns an effect for removing the event listener.
187186onData :: ClientHttp2Stream -> (Buffer -> Effect Unit ) -> Effect (Effect Unit )
188- onData http2stream = Internal .onData (unsafeCoerce http2stream)
187+ onData http2stream = Internal .onData (upcastClientHttp2Stream http2stream)
189188
190189-- | https://nodejs.org/docs/latest/api/net.html#event-end
191190-- |
192- -- | Listen for one event, then remove the event listener.
191+ -- | Listen for one event, call the callback, then remove the event listener.
193192-- |
194193-- | Returns an effect for removing the event listener before the event
195194-- | is raised.
196195onceEnd :: ClientHttp2Stream -> Effect Unit -> Effect (Effect Unit )
197- onceEnd http2stream = Internal .onceEnd (unsafeCoerce http2stream)
196+ onceEnd http2stream = Internal .onceEnd (upcastClientHttp2Stream http2stream)
198197
199198-- | https://nodejs.org/docs/latest/api/http2.html#http2streamclosecode-callback
200199closeStream :: ClientHttp2Stream -> Int -> Effect Unit -> Effect Unit
201- closeStream stream = Internal .closeStream (unsafeCoerce stream)
200+ closeStream stream = Internal .closeStream (upcastClientHttp2Stream stream)
202201
203202-- | Coerce to a duplex stream.
204203toDuplex :: ClientHttp2Stream -> Duplex
0 commit comments