Created
October 30, 2015 08:04
-
-
Save dvdbng/f24fd724e357d6780ac8 to your computer and use it in GitHub Desktop.
Splash normalize headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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