fix(voice): 火山鉴权头精确大小写(X-Api-App-ID 免被 Go 规范化)
Go 的 Header.Set 会把 X-Api-App-ID 规范化成 X-Api-App-Id;改直接赋 map 保留精确 大小写,对齐官方 demo。鉴权方案已与参考实现(realtime_dialog demo)完全一致。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -17,13 +17,15 @@ const volcAppKey = "PlgvMymc7f3tQnJ6"
|
|||||||
// 新版 API Key(Access Key) + 资源 ID + 连接 ID。**不是** Authorization: Bearer(那是 OpenAI
|
// 新版 API Key(Access Key) + 资源 ID + 连接 ID。**不是** Authorization: Bearer(那是 OpenAI
|
||||||
// 兼容端点用的,流式二进制端点不认)。App ID 用于解析账号资源授权(缺它会 401 grant not found)。
|
// 兼容端点用的,流式二进制端点不认)。App ID 用于解析账号资源授权(缺它会 401 grant not found)。
|
||||||
func setVolcAuthHeaders(hdr http.Header, apiKey, appID, resourceID string) {
|
func setVolcAuthHeaders(hdr http.Header, apiKey, appID, resourceID string) {
|
||||||
hdr.Set("X-Api-App-Key", volcAppKey)
|
// 直接赋 map(不走 Set)以**保留精确大小写**:Go 的 Header.Set 会把 "X-Api-App-ID"
|
||||||
|
// 规范化成 "X-Api-App-Id",而火山网关按精确大小写匹配(官方 demo 用 X-Api-App-ID)。
|
||||||
|
hdr["X-Api-App-Key"] = []string{volcAppKey}
|
||||||
|
hdr["X-Api-Access-Key"] = []string{apiKey}
|
||||||
|
hdr["X-Api-Resource-Id"] = []string{resourceID}
|
||||||
|
hdr["X-Api-Connect-Id"] = []string{newConnectID()}
|
||||||
if appID != "" {
|
if appID != "" {
|
||||||
hdr.Set("X-Api-App-ID", appID)
|
hdr["X-Api-App-ID"] = []string{appID}
|
||||||
}
|
}
|
||||||
hdr.Set("X-Api-Access-Key", apiKey)
|
|
||||||
hdr.Set("X-Api-Resource-Id", resourceID)
|
|
||||||
hdr.Set("X-Api-Connect-Id", newConnectID())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handshakeDetail 从失败的 WS 握手响应里榨出可诊断信息:HTTP 状态 + 火山排障用的
|
// handshakeDetail 从失败的 WS 握手响应里榨出可诊断信息:HTTP 状态 + 火山排障用的
|
||||||
|
|||||||
Reference in New Issue
Block a user