@@ -199,6 +199,36 @@ export async function fetch(
199
199
}
200
200
} )
201
201
202
+ const abort = ( ) => invoke ( 'plugin:http|fetch_cancel' , { rid } )
203
+
204
+ // abort early here if needed
205
+ if ( signal ?. aborted ) {
206
+ // we don't care about the result of this proimse
207
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
208
+ abort ( )
209
+ throw new Error ( ERROR_REQUEST_CANCELLED )
210
+ }
211
+
212
+ signal ?. addEventListener ( 'abort' , ( ) => void abort ( ) )
213
+
214
+ interface FetchSendResponse {
215
+ status : number
216
+ statusText : string
217
+ headers : [ [ string , string ] ]
218
+ url : string
219
+ rid : number
220
+ }
221
+
222
+ const {
223
+ status,
224
+ statusText,
225
+ url,
226
+ headers : responseHeaders ,
227
+ rid : responseRid
228
+ } = await invoke < FetchSendResponse > ( 'plugin:http|fetch_send' , {
229
+ rid
230
+ } )
231
+
202
232
const readableStreamBody = new ReadableStream ( {
203
233
start : ( controller ) => {
204
234
const streamChannel = new Channel < ArrayBuffer | number [ ] > ( )
@@ -226,43 +256,14 @@ export async function fetch(
226
256
227
257
// run a non-blocking body stream fetch
228
258
invoke ( 'plugin:http|fetch_read_body' , {
229
- rid,
259
+ rid : responseRid ,
230
260
streamChannel
231
261
} ) . catch ( ( e ) => {
232
262
controller . error ( e )
233
263
} )
234
264
}
235
265
} )
236
266
237
- const abort = ( ) => invoke ( 'plugin:http|fetch_cancel' , { rid } )
238
-
239
- // abort early here if needed
240
- if ( signal ?. aborted ) {
241
- // we don't care about the result of this proimse
242
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
243
- abort ( )
244
- throw new Error ( ERROR_REQUEST_CANCELLED )
245
- }
246
-
247
- signal ?. addEventListener ( 'abort' , ( ) => void abort ( ) )
248
-
249
- interface FetchSendResponse {
250
- status : number
251
- statusText : string
252
- headers : [ [ string , string ] ]
253
- url : string
254
- rid : number
255
- }
256
-
257
- const {
258
- status,
259
- statusText,
260
- url,
261
- headers : responseHeaders
262
- } = await invoke < FetchSendResponse > ( 'plugin:http|fetch_send' , {
263
- rid
264
- } )
265
-
266
267
const res = new Response ( readableStreamBody , {
267
268
status,
268
269
statusText
0 commit comments