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:19:07 -04:00
parent 948fba3a2c
commit 874bba59d3
2 changed files with 12 additions and 6 deletions

View File

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

View File

@ -104,13 +104,19 @@ export class Http {
} }
}); });
resp.data = new Response(stream); const data = new Response(stream);
resp.body = data.body;
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('json')) resp.data = <T>await resp.data.json(); if(content?.includes('application')) resp.data = <T>await data.blob();
else if(content?.includes('text')) resp.data = <T>await resp.data.text(); 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('application')) resp.data = <T>await resp.data.blob(); else if(content?.includes('text')) resp.data = <T>await data.text();
} }
if(resp.ok) res(resp); if(resp.ok) res(resp);