Messing around with http decoding
This commit is contained in:
parent
948fba3a2c
commit
874bba59d3
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.14.7",
|
||||
"version": "0.14.8",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
16
src/http.ts
16
src/http.ts
@ -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) {
|
||||
const content = resp.headers.get('Content-Type')?.toLowerCase();
|
||||
if(content?.includes('json')) resp.data = <T>await resp.data.json();
|
||||
else if(content?.includes('text')) resp.data = <T>await resp.data.text();
|
||||
else if(content?.includes('form')) resp.data = <T>await resp.data.formData();
|
||||
else if(content?.includes('application')) resp.data = <T>await resp.data.blob();
|
||||
if(content?.includes('application')) resp.data = <T>await data.blob();
|
||||
else if(content?.includes('form')) resp.data = <T>await data.formData();
|
||||
else if(content?.includes('json')) resp.data = <T>await data.json();
|
||||
else if(content?.includes('text')) resp.data = <T>await data.text();
|
||||
}
|
||||
|
||||
if(resp.ok) res(resp);
|
||||
|
Loading…
Reference in New Issue
Block a user