|
|
@ -265,51 +265,70 @@ class CommandProcessor { |
|
|
|
} |
|
|
|
if (msg.data.msg.name == 'corsFetch') { |
|
|
|
const { args } = msg.data.msg; |
|
|
|
const res = await ifetch(args[0], args[1]); |
|
|
|
// don't report progress because monkeys don't have a way to expose partial responses anyway
|
|
|
|
const headersStr = (res as any).responseHeaders; |
|
|
|
const headerObj = headerStringToObject(headersStr); |
|
|
|
try { |
|
|
|
const res = await ifetch(args[0], args[1]); |
|
|
|
// don't report progress because monkeys don't have a way to expose partial responses anyway
|
|
|
|
const headersStr = (res as any).responseHeaders; |
|
|
|
const headerObj = headerStringToObject(headersStr); |
|
|
|
|
|
|
|
this.processor.postMessage({ |
|
|
|
type: 'ipc', |
|
|
|
id, |
|
|
|
res: { |
|
|
|
this.processor.postMessage({ |
|
|
|
type: 'ipc', |
|
|
|
id, |
|
|
|
ok: res.ok || true, |
|
|
|
setRes: true, |
|
|
|
headers: headerObj, |
|
|
|
responseHeaders: headersStr, |
|
|
|
redirected: res.redirected, |
|
|
|
type: res.type, |
|
|
|
url: res.url, |
|
|
|
status: res.status, |
|
|
|
bodyUsed: res.bodyUsed, |
|
|
|
statusText: res.statusText, |
|
|
|
res: { |
|
|
|
id, |
|
|
|
ok: res.ok || true, |
|
|
|
setRes: true, |
|
|
|
headers: headerObj, |
|
|
|
responseHeaders: headersStr, |
|
|
|
redirected: res.redirected, |
|
|
|
type: res.type, |
|
|
|
url: res.url, |
|
|
|
status: res.status, |
|
|
|
bodyUsed: res.bodyUsed, |
|
|
|
statusText: res.statusText, |
|
|
|
} |
|
|
|
}); |
|
|
|
if (!args[1].method || ['GET', 'POST'].includes(args[1].method)) { |
|
|
|
const data = await res.arrayBuffer(); |
|
|
|
this.processor.postMessage({ |
|
|
|
type: 'ipc', |
|
|
|
id, |
|
|
|
res: { |
|
|
|
id, |
|
|
|
pushData: { |
|
|
|
data |
|
|
|
} |
|
|
|
} |
|
|
|
}, [data]); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (!args[1].method || ['GET', 'POST'].includes(args[1].method)) { |
|
|
|
const data = await res.arrayBuffer(); |
|
|
|
// let's hope these are delivered in order :%)
|
|
|
|
this.processor.postMessage({ |
|
|
|
type: 'ipc', |
|
|
|
id, |
|
|
|
res: { |
|
|
|
id, |
|
|
|
pushData: { |
|
|
|
data |
|
|
|
} |
|
|
|
} |
|
|
|
}, [data]); |
|
|
|
} |
|
|
|
// let's hope these are delivered in order :%)
|
|
|
|
this.processor.postMessage({ |
|
|
|
type: 'ipc', |
|
|
|
id, |
|
|
|
res: { |
|
|
|
}, []); |
|
|
|
} catch (e) { |
|
|
|
this.processor.postMessage({ |
|
|
|
type: 'ipc', |
|
|
|
id, |
|
|
|
pushData: { |
|
|
|
res: { |
|
|
|
id, |
|
|
|
ok: false, |
|
|
|
setRes: true, |
|
|
|
headers: {}, |
|
|
|
responseHeaders: '', |
|
|
|
redirected: false, |
|
|
|
status: 400, |
|
|
|
bodyUsed: false, |
|
|
|
statusText: 'shit broke', |
|
|
|
} |
|
|
|
} |
|
|
|
}, []); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// ignore other commands
|
|
|
|
} |
|
|
|