Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d00968d0
authored
Apr 23, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix "HTTP decompression failed"
parent
03930132
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
common/constants.go
+1
-1
controller/relay.go
+5
-4
No files found.
common/constants.go
View file @
d00968d0
...
...
@@ -108,7 +108,7 @@ const (
ChannelTypeOhMyGPT
=
7
)
var
Channel
Host
s
=
[]
string
{
var
Channel
BaseURL
s
=
[]
string
{
""
,
// 0
"https://api.openai.com"
,
// 1
"https://openai.api2d.net"
,
// 2
...
...
controller/relay.go
View file @
d00968d0
...
...
@@ -10,8 +10,8 @@ import (
func
Relay
(
c
*
gin
.
Context
)
{
channelType
:=
c
.
GetInt
(
"channel"
)
host
:=
common
.
ChannelHost
s
[
channelType
]
req
,
err
:=
http
.
NewRequest
(
c
.
Request
.
Method
,
fmt
.
Sprintf
(
"%s%s"
,
host
,
c
.
Request
.
URL
.
String
()),
c
.
Request
.
Body
)
baseURL
:=
common
.
ChannelBaseURL
s
[
channelType
]
req
,
err
:=
http
.
NewRequest
(
c
.
Request
.
Method
,
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
c
.
Request
.
URL
.
String
()),
c
.
Request
.
Body
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"error"
:
gin
.
H
{
...
...
@@ -22,6 +22,9 @@ func Relay(c *gin.Context) {
return
}
req
.
Header
=
c
.
Request
.
Header
.
Clone
()
// Fix HTTP Decompression failed
// https://github.com/stoplightio/prism/issues/1064#issuecomment-824682360
req
.
Header
.
Del
(
"Accept-Encoding"
)
client
:=
&
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
req
)
...
...
@@ -38,8 +41,6 @@ func Relay(c *gin.Context) {
c
.
Writer
.
Header
()
.
Set
(
k
,
v
[
0
])
}
_
,
err
=
io
.
Copy
(
c
.
Writer
,
resp
.
Body
)
//body, err := io.ReadAll(resp.Body)
//_, err = c.Writer.Write(body)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"error"
:
gin
.
H
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment