From bf8426952079e9a116ad0e273c73612f0fa00e77 Mon Sep 17 00:00:00 2001
From: akira-cn <akira.cn@gmail.com>
Date: Fri, 10 Nov 2023 20:38:53 +0800
Subject: [PATCH 1/2] fix: remove the content-encoding header

---
 app/api/common.ts | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/app/api/common.ts b/app/api/common.ts
index adec611b2..e95bb4836 100644
--- a/app/api/common.ts
+++ b/app/api/common.ts
@@ -106,6 +106,12 @@ export async function requestOpenai(req: NextRequest) {
     // to disable nginx buffering
     newHeaders.set("X-Accel-Buffering", "no");
 
+    // The latest version of the OpenAI API forced the content-encoding to be "br" in json response
+    // So if the streaming is disabled, we need to remove the content-encoding header
+    // But vercel uses gzip to compress the response
+    // So we need to remove the content-encoding header
+    newHeaders.delete("content-encoding");
+
     return new Response(res.body, {
       status: res.status,
       statusText: res.statusText,

From dd6e79922a455862d6ae5c0a9469680d5c9e1d90 Mon Sep 17 00:00:00 2001
From: akira-cn <akira.cn@gmail.com>
Date: Fri, 10 Nov 2023 20:42:12 +0800
Subject: [PATCH 2/2] fix: remove the content-encoding header

---
 app/api/common.ts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/api/common.ts b/app/api/common.ts
index e95bb4836..9f786c403 100644
--- a/app/api/common.ts
+++ b/app/api/common.ts
@@ -108,8 +108,8 @@ export async function requestOpenai(req: NextRequest) {
 
     // The latest version of the OpenAI API forced the content-encoding to be "br" in json response
     // So if the streaming is disabled, we need to remove the content-encoding header
-    // But vercel uses gzip to compress the response
-    // So we need to remove the content-encoding header
+    // Because Vercel uses gzip to compress the response, if we don't remove the content-encoding header
+    // The browser will try to decode the response with brotli and fail
     newHeaders.delete("content-encoding");
 
     return new Response(res.body, {