Skip to content

Instantly share code, notes, and snippets.

@dvdbng
Created October 30, 2015 08:04
Show Gist options
  • Save dvdbng/f24fd724e357d6780ac8 to your computer and use it in GitHub Desktop.
Save dvdbng/f24fd724e357d6780ac8 to your computer and use it in GitHub Desktop.
Splash normalize headers
-- x-FOO-bAr -> X-Foo-Bar
function normalize_header(name)
name = upper(sub(name, 1, 1)) .. lower(sub(name, 2))
while true do
local start,fin = find(name, '-[a-z]')
if start ~= nil then
name = sub(name, 1, start) .. upper(sub(name, fin, fin)) .. sub(name, fin+1)
else
break
end
end
return name
end
function normalize_headers(headers)
local res = {}
for name,value in pairs(headers) do
res[normalize_header(name)] = value
end
return res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment