Created
November 2, 2012 02:56
-
-
Save moonbingbing/3998396 to your computer and use it in GitHub Desktop.
parse content-Type multipart/form-data according to RFC2388
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
--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