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

perf(pdk) faster request.get_header #8716

Merged
merged 9 commits into from
May 18, 2022
Merged
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
7 changes: 3 additions & 4 deletions kong/pdk/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local phase_checker = require "kong.pdk.private.phases"


local ngx = ngx
local var = ngx.var
local sub = string.sub
local find = string.find
local lower = string.lower
chronolaw marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -568,10 +569,8 @@ local function new(self)
error("header name must be a string", 2)
end

local header_value = _REQUEST.get_headers()[name]
if type(header_value) == "table" then
return header_value[1]
end
-- Do not localize ngx.re.gsub! It will crash because ngx.re is monkey patched.
StarlightIbuki marked this conversation as resolved.
Show resolved Hide resolved
local header_value = var["http_" .. ngx.re.gsub(name, "-", "_", "jo")]

return header_value
end
Expand Down
4 changes: 2 additions & 2 deletions t/01-pdk/04-request/13-get_header.t
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ X-Foo-Header: ''



=== TEST 5: request.get_header() returns nil when requested header does not fit in default max_headers
=== TEST 5: request.get_header() have no limit on header numbers
--- http_config eval: $t::Util::HttpConfig
--- config
location = /t {
Expand Down Expand Up @@ -133,7 +133,7 @@ X-Foo-Header: ''
--- request
GET /t
--- response_body
accept header value: nil
accept header value: text/html
--- no_error_log
[error]

Expand Down