fix: Node.js TLS 代理按 proxy_hosts 白名单过滤 + 诊断日志
Some checks failed
CI / test (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
Security Scan / backend-security (push) Has been cancelled
Security Scan / frontend-security (push) Has been cancelled

- 新增 proxy_hosts 配置:可配置需要走 Node.js 代理的主机列表
- 默认仅代理 api.anthropic.com,Gemini/Sora 走原路径
- 添加 warn 级别诊断日志,输出请求的 scheme/host/hostname/should_route
- 用于定位 Anthropic 请求未命中 Node.js 代理的原因
This commit is contained in:
win 2026-03-22 01:36:12 +08:00
parent c6a282c2e7
commit fbcaab03da

View File

@ -125,8 +125,18 @@ func NewHTTPUpstream(cfg *config.Config) service.HTTPUpstream {
// - inFlight > 0 的客户端不会被淘汰,确保活跃请求不被中断
func (s *httpUpstreamService) Do(req *http.Request, proxyURL string, accountID int64, accountConcurrency int) (*http.Response, error) {
// Node.js TLS 代理:仅拦截白名单内的上游主机
if s.isNodeTLSProxyEnabled() && s.shouldRouteViaNodeProxy(req) {
return s.doViaNodeTLSProxy(req, accountID, accountConcurrency)
if s.isNodeTLSProxyEnabled() {
if req != nil && req.URL != nil {
slog.Warn("node_tls_proxy_check",
"scheme", req.URL.Scheme,
"host", req.URL.Host,
"hostname", req.URL.Hostname(),
"should_route", s.shouldRouteViaNodeProxy(req),
)
}
if s.shouldRouteViaNodeProxy(req) {
return s.doViaNodeTLSProxy(req, accountID, accountConcurrency)
}
}
if err := s.validateRequestHost(req); err != nil {