upstream asis
This commit is contained in:
3
auth.go
3
auth.go
@@ -20,7 +20,8 @@ func handleAuth(c *gin.Context) error {
|
||||
|
||||
authorization = strings.Trim(authorization[len("Bearer"):], " ")
|
||||
log.Println("Received authorization", authorization)
|
||||
if authorization != authConfig.Value {
|
||||
|
||||
if authConfig.Value != "asis" && authorization != authConfig.Value {
|
||||
err = errors.New("wrong authorization header")
|
||||
c.AbortWithError(403, err)
|
||||
return err
|
||||
|
||||
8
main.go
8
main.go
@@ -185,7 +185,11 @@ func main() {
|
||||
out.URL.Path = in.URL.Path
|
||||
out.Header = http.Header{}
|
||||
out.Header.Set("Host", remote.Host)
|
||||
out.Header.Set("Authorization", "Bearer "+upstream.SK)
|
||||
if upstream.SK == "asis" {
|
||||
out.Header.Set("Authorization", c.Request.Header.Get("Authorization"))
|
||||
} else {
|
||||
out.Header.Set("Authorization", "Bearer "+upstream.SK)
|
||||
}
|
||||
out.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
@@ -230,7 +234,7 @@ func main() {
|
||||
}
|
||||
content := fmt.Sprintf("[%s] OpenAI 转发出错 ID: %d... 密钥: [%s] 上游: [%s] 错误: %s\n---\n%s",
|
||||
c.ClientIP(),
|
||||
upstream.ID, upstream.SK[:10], upstream.Endpoint, err.Error(),
|
||||
upstream.ID, upstream.SK, upstream.Endpoint, err.Error(),
|
||||
strings.Join(upstreamDescriptions, "\n"),
|
||||
)
|
||||
go sendMatrixMessage(content)
|
||||
|
||||
Reference in New Issue
Block a user