Skip to content

Commit

Permalink
fix: add http2 test
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed Sep 11, 2024
1 parent 76c4512 commit f82c368
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion spec/02-integration/05-proxy/24-buffered_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ for _, strategy in helpers.each_strategy() do
elseif client_protocol == "https" then
proxy_client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
proxy_client = helpers.proxy_ssl_client(nil, nil, true)
proxy_client = helpers.proxy_ssl_client(nil, nil, 2)
end
proxy_ssl_client = helpers.proxy_ssl_client()
end)
Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/38-ai-proxy/02-openai_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, true)
client = helpers.proxy_ssl_client(nil, nil, 2)
end
-- Note: if file is removed instead of trunacted, file-log ends writing to a unlinked file handle
truncate_file(FILE_LOG_PATH_STATS_ONLY)
Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/38-ai-proxy/04-cohere_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, true)
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/38-ai-proxy/05-azure_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, true)
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, true)
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/38-ai-proxy/07-llama2_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, true)
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, true)
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, true)
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

Expand Down
28 changes: 16 additions & 12 deletions spec/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ function resty_http_proxy_mt:send(opts, is_reopen)
opts.path = opts.path .. "?" .. qs
opts.query = nil
end
if self.options.http_version and self.options.http_version == 2.0 then
if self.options.http_version and self.options.http_version == 2 then
local url = self.options.scheme .. "://" .. self.options.host .. ":" .. self.options.port .. opts.path
local reqwest_opt = {
version = 2,
Expand Down Expand Up @@ -645,7 +645,7 @@ function resty_http_proxy_mt:_connect()
opts.read_timeout = CONSTANTS.TEST_COVERAGE_TIMEOUT * 1000
end

if opts.http_version and opts.http_version == 2.0 then
if opts.http_version and opts.http_version == 2 then
return
end

Expand Down Expand Up @@ -783,12 +783,15 @@ end
-- @param timeout (optional, number) the timeout to use
-- @param forced_port (optional, number) if provided will override the port in
-- the Kong configuration with this port
local function proxy_client(timeout, forced_port, forced_ip, http2)
-- @param forced_ip (optional, string) if provided will override the ip in
-- the Kong configuration with this ip
-- @param http_version (optional, number) the http version to use
local function proxy_client(timeout, forced_port, forced_ip, http_version)
local proxy_ip = get_proxy_ip(false)
local proxy_port = get_proxy_port(false)
local http_version
if http2 then
http_version = 2.0
local ihttp_version
if http_version == 2 then
ihttp_version = 2
proxy_ip = get_proxy_ip(false, true)
proxy_port = get_proxy_port(false, true)
end
Expand All @@ -799,7 +802,7 @@ local function proxy_client(timeout, forced_port, forced_ip, http2)
host = forced_ip or proxy_ip,
port = forced_port or proxy_port,
timeout = timeout or 60000,
http_version = http_version,
http_version = ihttp_version,
})
end

Expand All @@ -808,12 +811,13 @@ end
-- @function proxy_ssl_client
-- @param timeout (optional, number) the timeout to use
-- @param sni (optional, string) the sni to use
local function proxy_ssl_client(timeout, sni, http2)
-- @param http_version (optional, number) the http version to use
local function proxy_ssl_client(timeout, sni, http_version)
local proxy_ip = get_proxy_ip(true, true)
local proxy_port = get_proxy_port(true, true)
local http_version
if http2 then
http_version = 2.0
local ihttp_version
if http_version == 2 then
ihttp_version = 2
proxy_ip = get_proxy_ip(true, true)
proxy_port = get_proxy_port(true, true)
end
Expand All @@ -825,7 +829,7 @@ local function proxy_ssl_client(timeout, sni, http2)
timeout = timeout or 60000,
ssl_verify = false,
ssl_server_name = sni,
http_version = http_version,
http_version = ihttp_version,
})
return client
end
Expand Down

0 comments on commit f82c368

Please sign in to comment.