From a3b34ef03f6de5a8d8b44dcd8d92049aa0bbab30 Mon Sep 17 00:00:00 2001
From: ztimson <zaktimson@gmail.com>
Date: Tue, 18 Feb 2025 16:04:18 -0500
Subject: [PATCH] Fixed http no decode

---
 package.json |  2 +-
 src/http.ts  | 29 ++++++++++++++++++++++-------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/package.json b/package.json
index 39b7db3..e461e1a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "@ztimson/utils",
-	"version": "0.23.11",
+	"version": "0.23.12",
 	"description": "Utility library",
 	"author": "Zak Timson",
 	"license": "MIT",
diff --git a/src/http.ts b/src/http.ts
index 230d478..80f3ae4 100644
--- a/src/http.ts
+++ b/src/http.ts
@@ -22,6 +22,22 @@ export type HttpDefaults = {
 	url?: string;
 }
 
+class HttpResponse<T = any> extends Response {
+	data?: T
+	ok!: boolean;
+	redirected!: boolean;
+	type!: ResponseType;
+	url!: string;
+
+	constructor(resp: Response, stream: ReadableStream) {
+		super(stream, {headers: resp.headers, status: resp.status, statusText: resp.statusText});
+		this.ok = resp.ok;
+		this.redirected = resp.redirected;
+		this.type = resp.type;
+		this.url = resp.url;
+	}
+}
+
 export class Http {
 	private static interceptors: {[key: string]: HttpInterceptor} = {};
 
@@ -101,18 +117,17 @@ export class Http {
 									push();
 								}).catch((error: any) => controller.error(error));
 							}
-
 							push();
 						}
 					});
 
-					resp.data = new Response(stream);
-					if(opts.decode == null || opts.decode) {
+					resp = new HttpResponse<T>(resp, stream);
+					if(opts.decode !== false) {
 						const content = resp.headers.get('Content-Type')?.toLowerCase();
-						if(content?.includes('form')) resp.data = <T>await resp.data.formData();
-						else 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('application')) resp.data = <T>await resp.data.blob();
+						if(content?.includes('form')) resp.data = <T>await resp.formData();
+						else if(content?.includes('json')) resp.data = <T>await resp.json();
+						else if(content?.includes('text')) resp.data = <T>await resp.text();
+						else if(content?.includes('application')) resp.data = <T>await resp.blob();
 					}
 
 					if(resp.ok) res(resp);