@@ -41,7 +41,6 @@ module Node.HTTP2.Client
41
41
, request
42
42
, onceErrorSession
43
43
, onceResponse
44
- , onStream
45
44
, onceStream
46
45
, onceHeaders
47
46
, closeSession
@@ -64,6 +63,7 @@ import Effect (Effect)
64
63
import Effect.Exception (Error )
65
64
import Node.Buffer (Buffer )
66
65
import Node.HTTP2 (Flags , HeadersObject , OptionsObject )
66
+ import Node.HTTP2.Internal (Http2Session , Http2Stream )
67
67
import Node.HTTP2.Internal as Internal
68
68
import Node.Net.Socket (Socket )
69
69
import Node.Stream (Duplex )
@@ -75,6 +75,9 @@ import Unsafe.Coerce (unsafeCoerce)
75
75
-- | See [__Class: ClientHttp2Session__](https://nodejs.org/docs/latest/api/http2.html#class-clienthttp2session)
76
76
foreign import data ClientHttp2Session :: Type
77
77
78
+ upcastClientHttp2Session :: ClientHttp2Session -> Http2Session
79
+ upcastClientHttp2Session = unsafeCoerce
80
+
78
81
-- | https://nodejs.org/docs/latest/api/http2.html#http2connectauthority-options-listener
79
82
foreign import connect :: URL -> OptionsObject -> (ClientHttp2Session -> Socket -> Effect Unit ) -> Effect ClientHttp2Session
80
83
@@ -89,6 +92,9 @@ foreign import onceReady :: Socket -> (Effect Unit) -> Effect (Effect Unit)
89
92
-- | See [__Class: ClientHttp2Stream__](https://nodejs.org/docs/latest/api/http2.html#class-clienthttp2stream)
90
93
foreign import data ClientHttp2Stream :: Type
91
94
95
+ upcastClientHttp2Stream :: ClientHttp2Stream -> Http2Stream
96
+ upcastClientHttp2Stream = unsafeCoerce
97
+
92
98
-- |https://nodejs.org/docs/latest/api/http2.html#clienthttp2sessionrequestheaders-options
93
99
foreign import request :: ClientHttp2Session -> HeadersObject -> OptionsObject -> Effect ClientHttp2Stream
94
100
@@ -97,19 +103,19 @@ foreign import destroy :: ClientHttp2Stream -> Effect Unit
97
103
98
104
-- | https://nodejs.org/docs/latest/api/http2.html#http2sessionclosecallback
99
105
closeSession :: ClientHttp2Session -> Effect Unit -> Effect Unit
100
- closeSession http2session = Internal .closeSession (unsafeCoerce http2session)
106
+ closeSession http2session = Internal .closeSession (upcastClientHttp2Session http2session)
101
107
102
108
-- | https://nodejs.org/docs/latest/api/http2.html#event-response
103
109
-- |
104
- -- | Listen for one event, then remove the event listener.
110
+ -- | Listen for one event, call the callback, then remove the event listener.
105
111
-- |
106
112
-- | Returns an effect for removing the event listener before the event
107
113
-- | is raised.
108
114
foreign import onceResponse :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effect Unit ) -> Effect (Effect Unit )
109
115
110
116
-- | https://nodejs.org/docs/latest/api/http2.html#event-headers
111
117
-- |
112
- -- | Listen for one event, then remove the event listener.
118
+ -- | Listen for one event, call the callback, then remove the event listener.
113
119
-- |
114
120
-- | Returns an effect for removing the event listener before the event
115
121
-- | is raised.
@@ -119,38 +125,31 @@ foreign import onceHeaders :: ClientHttp2Stream -> (HeadersObject -> Flags -> Ef
119
125
-- |
120
126
-- | https://nodejs.org/docs/latest/api/http2.html#push-streams-on-the-client
121
127
-- |
122
- -- | Listen for one event, then remove the event listener.
128
+ -- | Listen for one event, call the callback, then remove the event listener.
123
129
-- |
124
130
-- | 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
130
131
-- |
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 )
136
135
137
136
-- | https://nodejs.org/docs/latest/api/http2.html#event-error
138
137
-- |
139
- -- | Listen for one event, then remove the event listener.
138
+ -- | Listen for one event, call the callback, then remove the event listener.
140
139
-- |
141
140
-- | Returns an effect for removing the event listener before the event
142
141
-- | is raised.
143
142
onceErrorSession :: ClientHttp2Session -> (Error -> Effect Unit ) -> Effect (Effect Unit )
144
- onceErrorSession http2session = Internal .onceEmitterError (unsafeCoerce http2session)
143
+ onceErrorSession http2session = Internal .onceSessionEmitterError (upcastClientHttp2Session http2session)
145
144
146
145
-- | https://nodejs.org/docs/latest/api/http2.html#event-error_1
147
146
-- |
148
- -- | Listen for one event, then remove the event listener.
147
+ -- | Listen for one event, call the callback, then remove the event listener.
149
148
-- |
150
149
-- | Returns an effect for removing the event listener before the event
151
150
-- | is raised.
152
151
onceErrorStream :: ClientHttp2Stream -> (Error -> Effect Unit ) -> Effect (Effect Unit )
153
- onceErrorStream http2stream = Internal .onceEmitterError (unsafeCoerce http2stream)
152
+ onceErrorStream http2stream = Internal .onceStreamEmitterError (upcastClientHttp2Stream http2stream)
154
153
155
154
-- | https://nodejs.org/docs/latest/api/http2.html#event-push
156
155
-- |
@@ -159,46 +158,46 @@ foreign import oncePush :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effec
159
158
160
159
-- | https://nodejs.org/docs/latest/api/http2.html#event-trailers
161
160
-- |
162
- -- | Listen for one event, then remove the event listener.
161
+ -- | Listen for one event, call the callback, then remove the event listener.
163
162
-- |
164
163
-- | Returns an effect for removing the event listener before the event
165
164
-- | is raised.
166
165
onceTrailers :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effect Unit ) -> Effect (Effect Unit )
167
- onceTrailers http2stream = Internal .onceTrailers (unsafeCoerce http2stream)
166
+ onceTrailers http2stream = Internal .onceTrailers (upcastClientHttp2Stream http2stream)
168
167
169
168
-- | https://nodejs.org/docs/latest/api/http2.html#event-wanttrailers
170
169
-- |
171
- -- | Listen for one event, then remove the event listener.
170
+ -- | Listen for one event, call the callback, then remove the event listener.
172
171
-- |
173
172
-- | Returns an effect for removing the event listener before the event
174
173
-- | is raised.
175
174
onceWantTrailers :: ClientHttp2Stream -> Effect Unit -> Effect (Effect Unit )
176
- onceWantTrailers http2stream = Internal .onceWantTrailers (unsafeCoerce http2stream)
175
+ onceWantTrailers http2stream = Internal .onceWantTrailers (upcastClientHttp2Stream http2stream)
177
176
178
177
-- | https://nodejs.org/docs/latest/api/http2.html#http2streamsendtrailersheaders
179
178
-- |
180
179
-- | > 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.
181
180
sendTrailers :: ClientHttp2Stream -> HeadersObject -> Effect Unit
182
- sendTrailers http2stream = Internal .sendTrailers (unsafeCoerce http2stream)
181
+ sendTrailers http2stream = Internal .sendTrailers (upcastClientHttp2Stream http2stream)
183
182
184
183
-- | https://nodejs.org/docs/latest/api/stream.html#event-data
185
184
-- |
186
185
-- | Returns an effect for removing the event listener.
187
186
onData :: ClientHttp2Stream -> (Buffer -> Effect Unit ) -> Effect (Effect Unit )
188
- onData http2stream = Internal .onData (unsafeCoerce http2stream)
187
+ onData http2stream = Internal .onData (upcastClientHttp2Stream http2stream)
189
188
190
189
-- | https://nodejs.org/docs/latest/api/net.html#event-end
191
190
-- |
192
- -- | Listen for one event, then remove the event listener.
191
+ -- | Listen for one event, call the callback, then remove the event listener.
193
192
-- |
194
193
-- | Returns an effect for removing the event listener before the event
195
194
-- | is raised.
196
195
onceEnd :: ClientHttp2Stream -> Effect Unit -> Effect (Effect Unit )
197
- onceEnd http2stream = Internal .onceEnd (unsafeCoerce http2stream)
196
+ onceEnd http2stream = Internal .onceEnd (upcastClientHttp2Stream http2stream)
198
197
199
198
-- | https://nodejs.org/docs/latest/api/http2.html#http2streamclosecode-callback
200
199
closeStream :: ClientHttp2Stream -> Int -> Effect Unit -> Effect Unit
201
- closeStream stream = Internal .closeStream (unsafeCoerce stream)
200
+ closeStream stream = Internal .closeStream (upcastClientHttp2Stream stream)
202
201
203
202
-- | Coerce to a duplex stream.
204
203
toDuplex :: ClientHttp2Stream -> Duplex
0 commit comments