@@ -9,8 +9,8 @@ local getmetatable = getmetatable
9
9
local type = type
10
10
local lower = string.lower
11
11
local upper = string.upper
12
- local sub = string.sub
13
12
local ngx_re = ngx .re
13
+ local re_gsub = ngx_re .gsub
14
14
15
15
local normalize_exceptions = {
16
16
etag = ' ETag'
@@ -27,20 +27,17 @@ local headers_mt = {
27
27
end
28
28
}
29
29
30
- local capitalize = function (string )
31
- return upper (sub ( string , 1 , 1 )) .. sub ( string , 2 )
30
+ local capitalize = function (m )
31
+ return upper (m [ 0 ] )
32
32
end
33
33
34
- local regex_parts = [[ [^_-]+ ]]
34
+ local letter = [[ \b([a-z]) ]]
35
35
36
- local key_parts_capitalized = function (key )
37
- local parts = {}
36
+ local capitalize_header = function (key )
37
+ key = re_gsub (key , ' _' , ' -' , ' jo' )
38
+ key = re_gsub (key , letter , capitalize , ' jo' )
38
39
39
- for matches in ngx_re .gmatch (key , regex_parts , ' jo' ) do
40
- insert (parts , capitalize (matches [0 ]))
41
- end
42
-
43
- return parts
40
+ return key
44
41
end
45
42
46
43
headers .normalize_key = function (key )
@@ -50,7 +47,7 @@ headers.normalize_key = function(key)
50
47
return exception
51
48
end
52
49
53
- return concat ( key_parts_capitalized ( key ), ' - ' )
50
+ return capitalize_header ( key )
54
51
end
55
52
56
53
local header_mt = {
0 commit comments