Multipart parsing library for OpenResty
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.ci
lib/resty
spec
.busted
.travis.yml
LICENSE
Makefile
README.md
lua-resty-multipart-0.0.1-1.rockspec
rbusted

README.md

lua-resty-multipart

Module Version Build Status

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.

Table of Contents

Motivation

TODO

Back to TOC

Usage

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())

Back to TOC

Installation

TODO

Back to TOC

Documentation

TODO

Back to TOC

License

Work licensed under the MIT License.

Back to TOC