Skip to content

Commit

Permalink
http_ng/headers: simplify capitalize method
Browse files Browse the repository at this point in the history
Avoid using regex. It's much more performant this way. Using Apicast in
echo mode, in a particular setup it went from ~3.5k rps to ~5k.
  • Loading branch information
davidor committed Nov 2, 2017
1 parent f896369 commit 93c73a9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apicast/src/resty/http_ng/headers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local getmetatable = getmetatable
local type = type
local lower = string.lower
local upper = string.upper
local sub = string.sub
local ngx_re = ngx.re

local normalize_exceptions = {
Expand All @@ -26,12 +27,12 @@ local headers_mt = {
end
}

local regex_first_letter = [[^\w]]
local upper_first_match = function(matches) return upper(matches[0]) end

local capitalize = function(string)
local str = ngx_re.sub(string, regex_first_letter, upper_first_match, 'jo')
return str
if string then
return upper(sub(string, 1, 1)) .. sub(string, 2)
else
return string
end
end

local regex_parts = [[[^_-]+]]
Expand Down

0 comments on commit 93c73a9

Please sign in to comment.