Skip to content

Commit 2cc57b5

Browse files
committed
Openresty Update: Fix headers ordering issues
When setting headers, the order is important in case of duplication, using tablex that keep the order as it was set. Signed-off-by: Eloy Coto <[email protected]>
1 parent 0af820d commit 2cc57b5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

gateway/src/resty/http_ng/headers.lua

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local lower = string.lower
1111
local upper = string.upper
1212
local ngx_re = ngx.re
1313
local re_gsub = ngx_re.gsub
14+
local tablex_pairmap = require('pl.tablex').pairmap
15+
local tablex_sort = require('pl.tablex').sort
1416

1517
local normalize_exceptions = {
1618
etag = 'ETag'
@@ -54,7 +56,7 @@ local header_mt = {
5456
__tostring = function(t)
5557
local tmp = {}
5658

57-
for k,v in pairs(t) do
59+
for k,v in tablex_sort(t) do
5860
if type(k) == 'string' then
5961
insert(tmp, k)
6062
elseif type(v) == 'string' then
@@ -76,13 +78,13 @@ end
7678

7779
headers.normalize = function(http_headers)
7880
http_headers = http_headers or {}
79-
80-
local normalized = {}
81-
for k,v in pairs(http_headers) do
82-
normalized[headers.normalize_key(k)] = headers.normalize_value(v)
81+
82+
local serialize = function(k,v)
83+
return headers.normalize_value(v), headers.normalize_key(k)
8384
end
8485

85-
return normalized
86+
-- Use tablex because it uses the same order as defined
87+
return tablex_pairmap(serialize, http_headers)
8688
end
8789

8890
headers.new = function(h)

0 commit comments

Comments
 (0)