multipart/form-data MIME type parser optimized for OpenResty with JIT PCRE.
Note: while this library is an improvement over some other ones out there,
it is not implemented in a streaming fashion unlike, for instance,
lua-resty-upload.
This means that your bodies must be accumulated in the Lua land, potentially
exhausting the Lua VM memory. We shall provide a resty.multipart.streaming
module for downstream/upstream streamed parsing.
TODO
Simple encoder/decoder:
local multipart = require 'resty.multipart'
-- decoding
local res = assert(multipart.unserialize(body?, boundary?))
for i, part in ipairs(res) do
print(part.name)
end
-- encoding
local body = assert(multipart.serialize({
{
name = 'part1',
headers = {['Content-Disposition'] = 'form-data; name="part1"'},
value = 'hello world'
},
{
name = 'part2',
headers = {['Content-Disposition'] = 'form-data; name="part2"'},
value = 'foo'
}
}), '------boundary')
Multipart helper:
local multipart = require 'resty.multipart'
local m = assert(multipart.new(body?, boundary?, content_type?))
-- decoding
local res = assert(m:decode())
-- modifying
assert(m:add('new_part', {['Content-Type'] = 'text/plain'}, 'hello world'))
assert(m:remove('name'))
-- encoding
local new_body = assert(m:encode())
TODO
TODO
Work licensed under the MIT License.