From 874bba59d30212dd52df117ccac7eb7ddef65060 Mon Sep 17 00:00:00 2001 From: ztimson Date: Tue, 13 Aug 2024 15:19:07 -0400 Subject: [PATCH] Messing around with http decoding --- package.json | 2 +- src/http.ts | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 4e78206..b433a31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.14.7", + "version": "0.14.8", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/http.ts b/src/http.ts index 43e1cae..5d21aeb 100644 --- a/src/http.ts +++ b/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 = await resp.data.json(); - else if(content?.includes('text')) resp.data = await resp.data.text(); - else if(content?.includes('form')) resp.data = await resp.data.formData(); - else if(content?.includes('application')) resp.data = await resp.data.blob(); + if(content?.includes('application')) resp.data = await data.blob(); + else if(content?.includes('form')) resp.data = await data.formData(); + else if(content?.includes('json')) resp.data = await data.json(); + else if(content?.includes('text')) resp.data = await data.text(); } if(resp.ok) res(resp);