Messing around with http decoding
All checks were successful
Build / Build NPM Project (push) Successful in 24s
Build / Tag Version (push) Successful in 7s

This commit is contained in:
Zakary Timson 2024-08-13 15:38:20 -04:00
parent 26c6084052
commit d587b92ea4
2 changed files with 6 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.14.9", "version": "0.14.10",
"description": "Utility library", "description": "Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@ -104,18 +104,13 @@ export class Http {
} }
}); });
const data = new Response(stream); resp.data = new Response(stream);
resp.blob = data.blob;
resp.formData = data.formData;
resp.json = data.json;
resp.text = data.text;
if(opts.decode !== false) { if(opts.decode !== false) {
const content = resp.headers.get('Content-Type')?.toLowerCase(); const content = resp.headers.get('Content-Type')?.toLowerCase();
if(content?.includes('application')) resp.data = <T>await data.blob(); if(content?.includes('application')) resp.data = <T>await resp.data.blob();
else if(content?.includes('form')) resp.data = <T>await data.formData(); else if(content?.includes('form')) resp.data = <T>await resp.data.formData();
else if(content?.includes('json')) resp.data = <T>await data.json(); else if(content?.includes('json')) resp.data = <T>await resp.data.json();
else if(content?.includes('text')) resp.data = <T>await data.text(); else if(content?.includes('text')) resp.data = <T>await resp.data.text();
} }
if(resp.ok) res(resp); if(resp.ok) res(resp);