fix(http): response with status code 204 (#960)

* Fix response construction with status code 204

* run pnpm build
pull/948/head
ppbl 1 year ago committed by GitHub
parent 8645a02aee
commit 3f81555fbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -155,15 +155,25 @@ export async function fetch(
rid,
});
const body = await invoke<number[]>("plugin:http|fetch_read_body", {
rid: responseRid,
});
const res = new Response(new Uint8Array(body), {
headers,
status,
statusText,
});
const body = await invoke<ArrayBuffer | number[]>(
"plugin:http|fetch_read_body",
{
rid: responseRid,
},
);
const res = new Response(
body instanceof ArrayBuffer && body.byteLength
? body
: body instanceof Array && body.length
? new Uint8Array(body)
: null,
{
headers,
status,
statusText,
},
);
// url is read only but seems like we can do this
Object.defineProperty(res, "url", { value: url });

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_PLUGIN_HTTP__=function(e){"use strict";async function t(e,t={},r){return window.__TAURI_INTERNALS__.invoke(e,t,r)}return"function"==typeof SuppressedError&&SuppressedError,e.fetch=async function(e,r){const n=r?.maxRedirections,i=r?.connectTimeout,a=r?.proxy;r&&(delete r.maxRedirections,delete r.connectTimeout,delete r.proxy);const o=r?.signal,s=new Request(e,r),u=await s.arrayBuffer(),c=u.byteLength?Array.from(new Uint8Array(u)):null,d=await t("plugin:http|fetch",{clientConfig:{method:s.method,url:s.url,headers:Array.from(s.headers.entries()),data:c,maxRedirections:n,connectTimeout:i,proxy:a}});o?.addEventListener("abort",(()=>{t("plugin:http|fetch_cancel",{rid:d})}));const{status:_,statusText:p,url:f,headers:l,rid:h}=await t("plugin:http|fetch_send",{rid:d}),y=await t("plugin:http|fetch_read_body",{rid:h}),T=new Response(new Uint8Array(y),{headers:l,status:_,statusText:p});return Object.defineProperty(T,"url",{value:f}),T},e}({});Object.defineProperty(window.__TAURI__,"http",{value:__TAURI_PLUGIN_HTTP__})}
if("__TAURI__"in window){var __TAURI_PLUGIN_HTTP__=function(e){"use strict";async function t(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}return"function"==typeof SuppressedError&&SuppressedError,e.fetch=async function(e,n){const r=n?.maxRedirections,i=n?.connectTimeout,a=n?.proxy;n&&(delete n.maxRedirections,delete n.connectTimeout,delete n.proxy);const o=n?.signal,s=new Request(e,n),u=await s.arrayBuffer(),c=u.byteLength?Array.from(new Uint8Array(u)):null,d=await t("plugin:http|fetch",{clientConfig:{method:s.method,url:s.url,headers:Array.from(s.headers.entries()),data:c,maxRedirections:r,connectTimeout:i,proxy:a}});o?.addEventListener("abort",(()=>{t("plugin:http|fetch_cancel",{rid:d})}));const{status:_,statusText:f,url:l,headers:p,rid:h}=await t("plugin:http|fetch_send",{rid:d}),y=await t("plugin:http|fetch_read_body",{rid:h}),T=new Response(y instanceof ArrayBuffer&&y.byteLength?y:y instanceof Array&&y.length?new Uint8Array(y):null,{headers:p,status:_,statusText:f});return Object.defineProperty(T,"url",{value:l}),T},e}({});Object.defineProperty(window.__TAURI__,"http",{value:__TAURI_PLUGIN_HTTP__})}

Loading…
Cancel
Save