Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(patchs): fix kong.request.enable_buffering PDK function cannot be used when dowstream uses HTTP/2. #13614

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OS := $(shell uname | awk '{print tolower($$0)}')
MACHINE := $(shell uname -m)

DEV_ROCKS = "busted 2.2.0" "busted-hjtest 0.0.5" "luacheck 1.2.0" "lua-llthreads2 0.1.6" "ldoc 1.5.0" "luacov 0.15.0"
DEV_ROCKS = "busted 2.2.0" "busted-hjtest 0.0.5" "luacheck 1.2.0" "lua-llthreads2 0.1.6" "ldoc 1.5.0" "luacov 0.15.0" "lua-reqwest 0.1.0"
WIN_SCRIPTS = "bin/busted" "bin/kong" "bin/kong-health"
BUSTED_ARGS ?= -v
TEST_CMD ?= bin/busted $(BUSTED_ARGS)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/bundle/ngx_lua-0.10.26/src/ngx_http_lua_subrequest.c b/bundle/ngx_lua-0.10.26/src/ngx_http_lua_subrequest.c
index f4db9aa..d887b28 100644
--- a/bundle/ngx_lua-0.10.26/src/ngx_http_lua_subrequest.c
+++ b/bundle/ngx_lua-0.10.26/src/ngx_http_lua_subrequest.c
@@ -172,12 +172,6 @@ ngx_http_lua_ngx_location_capture_multi(lua_State *L)
return luaL_error(L, "no request object found");
}

-#if (NGX_HTTP_V2)
- if (r->main->stream) {
- return luaL_error(L, "http2 requests not supported yet");
- }
-#endif
-
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (ctx == NULL) {
return luaL_error(L, "no ctx found");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message: |
Fixed an issue where the `kong.request.enable_buffering` cannot be used when dowstream use HTTP/2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fixed an issue where the `kong.request.enable_buffering` cannot be used when dowstream use HTTP/2.
Fixed an issue where the `kong.request.enable_buffering` can not be used when dowstream uses HTTP/2.

type: bugfix
scope: Core
9 changes: 2 additions & 7 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1228,21 +1228,16 @@ function Kong.access()


if ctx.buffered_proxying then
local version = ngx.req.http_version()
local upgrade = var.upstream_upgrade or ""
if version < 2 and upgrade == "" then
if upgrade == "" then
if has_timing then
req_dyn_hook_run_hook("timing", "after:access")
end

return Kong.response()
end

if version >= 2 then
ngx_log(ngx_NOTICE, "response buffering was turned off: incompatible HTTP version (", version, ")")
else
ngx_log(ngx_NOTICE, "response buffering was turned off: connection upgrade (", upgrade, ")")
end
ngx_log(ngx_NOTICE, "response buffering was turned off: connection upgrade (", upgrade, ")")

ctx.buffered_proxying = nil
end
Expand Down
7 changes: 0 additions & 7 deletions kong/pdk/service/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ local function new(self)
-- kong.service.request.enable_buffering()
request.enable_buffering = function()
check_phase(access_rewrite_balancer)

if ngx.req.http_version() >= 2 then
error("buffered proxying cannot currently be enabled with http/" ..
ngx.req.http_version() .. ", please use http/1.x instead", 2)
end


ngx.ctx.buffered_proxying = true
end

Expand Down
12 changes: 10 additions & 2 deletions spec/02-integration/05-proxy/24-buffered_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ local md5 = ngx.md5
local TCP_PORT = helpers.get_available_port()


for _, client_protocol in ipairs({ "http", "https", "http2" }) do
for _, strategy in helpers.each_strategy() do
describe("Buffered Proxying [#" .. strategy .. "]", function()
describe("Buffered Proxying [#" .. strategy .. "] [#" .. client_protocol .. "]", function()

-- TODO: http2 / grpc does not currently work with
-- ngx.location.capture that buffered proxying uses
Expand Down Expand Up @@ -155,7 +156,13 @@ for _, strategy in helpers.each_strategy() do
end)

before_each(function()
proxy_client = helpers.proxy_client()
if client_protocol == "http" then
proxy_client = helpers.proxy_client()
elseif client_protocol == "https" then
proxy_client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
proxy_client = helpers.proxy_ssl_client(nil, nil, 2)
end
proxy_ssl_client = helpers.proxy_ssl_client()
end)

Expand Down Expand Up @@ -272,3 +279,4 @@ for _, strategy in helpers.each_strategy() do
end)
end)
end
end
12 changes: 10 additions & 2 deletions spec/03-plugins/38-ai-proxy/02-openai_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ local _EXPECTED_CHAT_STATS = {
},
}

for _, client_protocol in ipairs({ "http", "https", "http2" }) do
for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "] [#" .. client_protocol .. "]", function()
local client

lazy_setup(function()
Expand Down Expand Up @@ -796,7 +797,13 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

before_each(function()
client = helpers.proxy_client()
if client_protocol == "http" then
client = helpers.proxy_client()
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
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)
truncate_file(FILE_LOG_PATH_NO_LOGS)
Expand Down Expand Up @@ -1647,3 +1654,4 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

end end
end
12 changes: 10 additions & 2 deletions spec/03-plugins/38-ai-proxy/03-anthropic_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ local deepcompare = require("pl.tablex").deepcompare
local PLUGIN_NAME = "ai-proxy"
local MOCK_PORT = helpers.get_available_port()

for _, client_protocol in ipairs({ "http", "https", "http2" }) do
for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "] [#" .. client_protocol .. "]", function()
local client

lazy_setup(function()
Expand Down Expand Up @@ -515,7 +516,13 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

before_each(function()
client = helpers.proxy_client()
if client_protocol == "http" then
client = helpers.proxy_client()
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, true)
end
end)

after_each(function()
Expand Down Expand Up @@ -781,3 +788,4 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

end end
end
13 changes: 10 additions & 3 deletions spec/03-plugins/38-ai-proxy/04-cohere_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ local pl_file = require "pl.file"
local PLUGIN_NAME = "ai-proxy"
local MOCK_PORT = helpers.get_available_port()

for _, client_protocol in ipairs({ "http", "https", "http2" }) do
for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
local client
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "] [#" .. client_protocol .. "]", function() local client

lazy_setup(function()
local bp = helpers.get_db_utils(strategy == "off" and "postgres" or strategy, nil, { PLUGIN_NAME })
Expand Down Expand Up @@ -390,7 +390,13 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

before_each(function()
client = helpers.proxy_client()
if client_protocol == "http" then
client = helpers.proxy_client()
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

after_each(function()
Expand Down Expand Up @@ -624,3 +630,4 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

end end
end
12 changes: 10 additions & 2 deletions spec/03-plugins/38-ai-proxy/05-azure_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ local pl_file = require "pl.file"
local PLUGIN_NAME = "ai-proxy"
local MOCK_PORT = helpers.get_available_port()

for _, client_protocol in ipairs({ "http", "https", "http2" }) do
for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "] [#" .. client_protocol .. "]", function()
local client

lazy_setup(function()
Expand Down Expand Up @@ -407,7 +408,13 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

before_each(function()
client = helpers.proxy_client()
if client_protocol == "http" then
client = helpers.proxy_client()
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

after_each(function()
Expand Down Expand Up @@ -650,3 +657,4 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

end end
end
12 changes: 10 additions & 2 deletions spec/03-plugins/38-ai-proxy/06-mistral_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ local pl_file = require "pl.file"
local PLUGIN_NAME = "ai-proxy"
local MOCK_PORT = helpers.get_available_port()

for _, client_protocol in ipairs({ "http", "https", "http2" }) do
for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "] [#" .. client_protocol .. "]", function()
local client

lazy_setup(function()
Expand Down Expand Up @@ -343,7 +344,13 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

before_each(function()
client = helpers.proxy_client()
if client_protocol == "http" then
client = helpers.proxy_client()
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

after_each(function()
Expand Down Expand Up @@ -512,3 +519,4 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

end end
end
13 changes: 11 additions & 2 deletions spec/03-plugins/38-ai-proxy/07-llama2_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ local pl_file = require "pl.file"
local PLUGIN_NAME = "ai-proxy"
local MOCK_PORT = helpers.get_available_port()

for _, client_protocol in ipairs({ "http", "https", "http2" }) do

for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "] [#" .. client_protocol .. "]", function()
local client

lazy_setup(function()
Expand Down Expand Up @@ -191,7 +193,13 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

before_each(function()
client = helpers.proxy_client()
if client_protocol == "http" then
client = helpers.proxy_client()
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

after_each(function()
Expand Down Expand Up @@ -443,3 +451,4 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

end end
end
12 changes: 10 additions & 2 deletions spec/03-plugins/38-ai-proxy/08-encoding_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ local plugin_conf = {
},
}

for _, client_protocol in ipairs({ "http", "https", "http2" }) do
for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "] [#" .. client_protocol .. "]", function()
local client

lazy_setup(function()
Expand Down Expand Up @@ -241,7 +242,13 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

before_each(function()
client = helpers.proxy_client()
if client_protocol == "http" then
client = helpers.proxy_client()
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

after_each(function()
Expand Down Expand Up @@ -369,3 +376,4 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
----

end end
end
12 changes: 10 additions & 2 deletions spec/03-plugins/38-ai-proxy/09-streaming_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ local http = require("resty.http")
local PLUGIN_NAME = "ai-proxy"
local MOCK_PORT = helpers.get_available_port()

for _, client_protocol in ipairs({ "http", "https", "http2" }) do
for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "] [#" .. client_protocol .. "]", function()
local client

lazy_setup(function()
Expand Down Expand Up @@ -500,7 +501,13 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

before_each(function()
client = helpers.proxy_client()
if client_protocol == "http" then
client = helpers.proxy_client()
elseif client_protocol == "https" then
client = helpers.proxy_ssl_client()
elseif client_protocol == "http2" then
client = helpers.proxy_ssl_client(nil, nil, 2)
end
end)

after_each(function()
Expand Down Expand Up @@ -812,3 +819,4 @@ for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
end)

end end
end
Loading
Loading