mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-27 16:07:02 +00:00
Merge pull request #5847 from wucm667/feat/issue-5826-cn-header-overrides
feat(accounts): support header overrides for CN providers
This commit is contained in:
@@ -9,8 +9,8 @@ import (
|
||||
"golang.org/x/net/http/httpguts"
|
||||
)
|
||||
|
||||
// 请求头覆写(header override):对 Anthropic / OpenAI 平台的 api_key 账号
|
||||
// 以及 Grok 平台的 api_key / oauth 账号生效。
|
||||
// 请求头覆写(header override):对 Anthropic / OpenAI / Kimi / Zhipu / DeepSeek
|
||||
// 平台的 api_key 账号,以及 Grok 平台的 api_key / oauth 账号生效。
|
||||
// 管理员在账号上配置一组 header name -> value,转发到上游前用配置值覆盖同名请求头
|
||||
// (匹配不区分大小写);value 为空的条目视为"未填写",不参与覆盖。
|
||||
const (
|
||||
@@ -70,14 +70,15 @@ func isHeaderOverrideBlockedName(lowerName string) bool {
|
||||
}
|
||||
|
||||
// IsHeaderOverrideEligible 报告账号类型是否支持请求头覆写。
|
||||
// Anthropic / OpenAI 仅开放 api_key 账号;Grok 额外开放 oauth 账号——
|
||||
// Anthropic / OpenAI / Kimi / Zhipu / DeepSeek 仅开放 api_key 账号;
|
||||
// Grok 额外开放 oauth 账号——
|
||||
// 订阅流量改发自定义转发地址时,通常需要补充中间层要求的准入头。
|
||||
func (a *Account) IsHeaderOverrideEligible() bool {
|
||||
if a == nil {
|
||||
return false
|
||||
}
|
||||
switch a.Platform {
|
||||
case PlatformAnthropic, PlatformOpenAI:
|
||||
case PlatformAnthropic, PlatformOpenAI, PlatformKimi, PlatformZhipu, PlatformDeepseek:
|
||||
return a.Type == AccountTypeAPIKey
|
||||
case PlatformGrok:
|
||||
return a.Type == AccountTypeAPIKey || a.Type == AccountTypeOAuth
|
||||
|
||||
@@ -27,8 +27,14 @@ func TestIsHeaderOverrideEligible(t *testing.T) {
|
||||
}{
|
||||
{"anthropic apikey", PlatformAnthropic, AccountTypeAPIKey, true},
|
||||
{"openai apikey", PlatformOpenAI, AccountTypeAPIKey, true},
|
||||
{"kimi apikey", PlatformKimi, AccountTypeAPIKey, true},
|
||||
{"zhipu apikey", PlatformZhipu, AccountTypeAPIKey, true},
|
||||
{"deepseek apikey", PlatformDeepseek, AccountTypeAPIKey, true},
|
||||
{"anthropic oauth", PlatformAnthropic, AccountTypeOAuth, false},
|
||||
{"openai oauth", PlatformOpenAI, AccountTypeOAuth, false},
|
||||
{"kimi oauth", PlatformKimi, AccountTypeOAuth, false},
|
||||
{"zhipu oauth", PlatformZhipu, AccountTypeOAuth, false},
|
||||
{"deepseek oauth", PlatformDeepseek, AccountTypeOAuth, false},
|
||||
{"gemini apikey", PlatformGemini, AccountTypeAPIKey, false},
|
||||
{"grok apikey", PlatformGrok, AccountTypeAPIKey, true},
|
||||
{"grok oauth", PlatformGrok, AccountTypeOAuth, true},
|
||||
|
||||
Reference in New Issue
Block a user