From b70cee960e8e5bdd98de04a1fa9bf812288cdbd5 Mon Sep 17 00:00:00 2001 From: spacewander Date: Fri, 18 Feb 2022 19:29:34 +0800 Subject: [PATCH] fix: should not limit the header number TODO: convert the remain `ngx.req.get_headers()[XXX]` to core.request.header(...) Signed-off-by: spacewander --- apisix/core/request.lua | 2 +- apisix/plugins/request-validation.lua | 4 ++-- t/core/request.t | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apisix/core/request.lua b/apisix/core/request.lua index c15ac62e2b57..1bd8aafee0f0 100644 --- a/apisix/core/request.lua +++ b/apisix/core/request.lua @@ -43,7 +43,7 @@ local function _headers(ctx) end local headers = ctx.headers if not headers then - headers = get_headers() + headers = get_headers(0) ctx.headers = headers end diff --git a/apisix/plugins/request-validation.lua b/apisix/plugins/request-validation.lua index e64a9cec372d..0b3b0f3e18f3 100644 --- a/apisix/plugins/request-validation.lua +++ b/apisix/plugins/request-validation.lua @@ -66,8 +66,8 @@ function _M.check_schema(conf) end -function _M.rewrite(conf) - local headers = ngx.req.get_headers() +function _M.rewrite(conf, ctx) + local headers = core.request.headers(ctx) if conf.header_schema then local ok, err = core.schema.check(conf.header_schema, headers) diff --git a/t/core/request.t b/t/core/request.t index 7d688c9886eb..0f0acb414a3b 100644 --- a/t/core/request.t +++ b/t/core/request.t @@ -422,3 +422,24 @@ the post form is too large: request body in temp file not supported POST /t --- response_body POST + + + +=== TEST 14: get header +--- config + location /t { + content_by_lua_block { + local core = require("apisix.core") + ngx.say(core.request.header(ngx.ctx, "X-101")) + } + } +--- more_headers eval +my $i = 1; +my $s; +while ($i <= 101) { + $s .= "X-$i:$i\n"; + $i++; +} +$s +--- response_body +101