Skip to content

Commit dc665af

Browse files
nic-6443shreemaan-abhishek
authored andcommitted
fix(ai-proxy): overwrite download request headers in lower case
Signed-off-by: Nic <qianyong@api7.ai>
1 parent 4230143 commit dc665af

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

apisix/plugins/ai-drivers/openai-base.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ local math = math
4040
local os = os
4141
local ipairs = ipairs
4242
local setmetatable = setmetatable
43+
local str_lower = string.lower
4344

4445
local HTTP_INTERNAL_SERVER_ERROR = ngx.HTTP_INTERNAL_SERVER_ERROR
4546
local HTTP_GATEWAY_TIMEOUT = ngx.HTTP_GATEWAY_TIMEOUT
@@ -255,7 +256,13 @@ local function construct_forward_headers(ext_opts_headers, ctx, token)
255256
"content-length"
256257
}
257258

258-
local headers = core.table.merge(core.request.headers(ctx), ext_opts_headers)
259+
-- make header keys lower case to overwrite downstream headers correctly,
260+
-- because downstream headers are lower case
261+
local opts_headers_lower = {}
262+
for k, v in pairs(ext_opts_headers or {}) do
263+
opts_headers_lower[str_lower(k)] = v
264+
end
265+
local headers = core.table.merge(core.request.headers(ctx), opts_headers_lower)
259266
headers["Content-Type"] = "application/json"
260267

261268
for _, h in ipairs(blacklist) do

t/plugin/ai-proxy.t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,3 +813,13 @@ test-type: header_forwarding
813813
--- error_code: 200
814814
--- response_body eval
815815
qr/"x-request-id":"[\d\w-]+"/
816+
817+
818+
819+
=== TEST 23: send request with Authorization header
820+
--- request
821+
POST /anything
822+
{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }
823+
--- more_headers
824+
Authorization: Bearer wrong token
825+
--- error_code: 200

0 commit comments

Comments
 (0)