fix: fetchNoCors and http_request data handling (#664)

This commit is contained in:
Lukas Senionis
2024-08-03 20:24:25 +03:00
committed by GitHub
parent adf5a76392
commit 3e50ce65a7
2 changed files with 17 additions and 11 deletions
+10 -6
View File
@@ -528,18 +528,22 @@ class PluginLoader extends Logger {
// Same syntax as fetch but only supports the url-based syntax and an object for headers since it's the most common usage pattern
fetchNoCors(input: string, init?: DeckyRequestInit | undefined): Promise<Response> {
const headers: { [name: string]: string } = {
...(init?.headers as { [name: string]: string }),
'X-Decky-Auth': deckyAuthToken,
'X-Decky-Fetch-URL': input,
const { headers: initHeaders = {}, ...restOfInit } = init || {};
const getPrefixedHeaders = () => {
let prefixedInitHeaders: { [name: string]: any } = {};
for (const [key, value] of Object.entries(initHeaders)) {
prefixedInitHeaders[`X-Decky-Header-${key}`] = value;
}
return prefixedInitHeaders;
};
const headers: { [name: string]: string } = getPrefixedHeaders();
if (init?.excludedHeaders) {
headers['X-Decky-Fetch-Excluded-Headers'] = init.excludedHeaders.join(', ');
}
return fetch('http://127.0.0.1:1337/fetch', {
...init,
return fetch(this.getExternalResourceURL(input), {
...restOfInit,
credentials: 'include',
headers,
});