Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parse content-Type multipart/form-data according to RFC2388
--parse content-Type multipart/form-data according to RFC2388.
function parse_form_protocol(query_data)
local result = {}
local boundary = get_boundary()
if boundary == nil then
return result
end
boundary = "--" .. boundary
local regex = [[name="(\w+)"\s+([\S\s]+?)\s+?]] .. boundary
for m in ngx.re.gmatch(query_data, regex) do
local name = m[1]
local value =m[2]
result[name] = value
end
return result
end
function get_boundary()
local header = ngx.var.content_type
if not header then
return nil
end
return string.match(header, ";%s+boundary=(%S+)")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.