mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-16 05:03:44 +08:00
feat: support custom http header
This commit is contained in:
@@ -146,6 +146,20 @@ func testChannel(channel *model.Channel, request ChatRequest) error {
|
||||
req.Header.Set("X-Remote-Addr", ip)
|
||||
}
|
||||
|
||||
custom_http_headers := channel.CustomHttpHeaders
|
||||
if custom_http_headers != "" {
|
||||
var custom_http_headers_map map[string]string
|
||||
err := json.Unmarshal([]byte(custom_http_headers), &custom_http_headers_map)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, value := range custom_http_headers_map {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -109,6 +109,20 @@ func relayImageHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
|
||||
req.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
||||
req.Header.Set("Accept", c.Request.Header.Get("Accept"))
|
||||
|
||||
custom_http_headers := c.GetString("custom_http_headers")
|
||||
if custom_http_headers != "" {
|
||||
var custom_http_headers_map map[string]string
|
||||
err := json.Unmarshal([]byte(custom_http_headers), &custom_http_headers_map)
|
||||
|
||||
if err != nil {
|
||||
return errorWrapper(err, "unmarshal_custom_http_headers_failed", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for key, value := range custom_http_headers_map {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -320,6 +320,20 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
||||
req.Header.Set("X-Remote-Addr", ip)
|
||||
}
|
||||
|
||||
custom_http_headers := c.GetString("custom_http_headers")
|
||||
if custom_http_headers != "" {
|
||||
var custom_http_headers_map map[string]string
|
||||
err := json.Unmarshal([]byte(custom_http_headers), &custom_http_headers_map)
|
||||
|
||||
if err != nil {
|
||||
return errorWrapper(err, "unmarshal_custom_http_headers_failed", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for key, value := range custom_http_headers_map {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user