Fix "HTTP decompression failed"
This commit is contained in:
parent
279ae8ad50
commit
b86e1dec64
@ -108,7 +108,7 @@ const (
|
|||||||
ChannelTypeOhMyGPT = 7
|
ChannelTypeOhMyGPT = 7
|
||||||
)
|
)
|
||||||
|
|
||||||
var ChannelHosts = []string{
|
var ChannelBaseURLs = []string{
|
||||||
"", // 0
|
"", // 0
|
||||||
"https://api.openai.com", // 1
|
"https://api.openai.com", // 1
|
||||||
"https://openai.api2d.net", // 2
|
"https://openai.api2d.net", // 2
|
||||||
|
@ -10,8 +10,8 @@ import (
|
|||||||
|
|
||||||
func Relay(c *gin.Context) {
|
func Relay(c *gin.Context) {
|
||||||
channelType := c.GetInt("channel")
|
channelType := c.GetInt("channel")
|
||||||
host := common.ChannelHosts[channelType]
|
baseURL := common.ChannelBaseURLs[channelType]
|
||||||
req, err := http.NewRequest(c.Request.Method, fmt.Sprintf("%s%s", host, c.Request.URL.String()), c.Request.Body)
|
req, err := http.NewRequest(c.Request.Method, fmt.Sprintf("%s%s", baseURL, c.Request.URL.String()), c.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"error": gin.H{
|
"error": gin.H{
|
||||||
@ -22,6 +22,9 @@ func Relay(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.Header = c.Request.Header.Clone()
|
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{}
|
client := &http.Client{}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
@ -38,8 +41,6 @@ func Relay(c *gin.Context) {
|
|||||||
c.Writer.Header().Set(k, v[0])
|
c.Writer.Header().Set(k, v[0])
|
||||||
}
|
}
|
||||||
_, err = io.Copy(c.Writer, resp.Body)
|
_, err = io.Copy(c.Writer, resp.Body)
|
||||||
//body, err := io.ReadAll(resp.Body)
|
|
||||||
//_, err = c.Writer.Write(body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"error": gin.H{
|
"error": gin.H{
|
||||||
|
Loading…
Reference in New Issue
Block a user