Skip to content

Instantly share code, notes, and snippets.

@moonbingbing
Created November 2, 2012 02:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moonbingbing/3998396 to your computer and use it in GitHub Desktop.
Save moonbingbing/3998396 to your computer and use it in GitHub Desktop.
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