Skip to content

Commit bfb468d

Browse files
committed
fix: use responseRid in invoke and build js
1 parent 99bd751 commit bfb468d

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

plugins/http/guest-js/index.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,36 @@ export async function fetch(
199199
}
200200
})
201201

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+
202232
const readableStreamBody = new ReadableStream({
203233
start: (controller) => {
204234
const streamChannel = new Channel<ArrayBuffer | number[]>()
@@ -226,43 +256,14 @@ export async function fetch(
226256

227257
// run a non-blocking body stream fetch
228258
invoke('plugin:http|fetch_read_body', {
229-
rid,
259+
rid: responseRid,
230260
streamChannel
231261
}).catch((e) => {
232262
controller.error(e)
233263
})
234264
}
235265
})
236266

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-
266267
const res = new Response(readableStreamBody, {
267268
status,
268269
statusText

0 commit comments

Comments
 (0)