Skip to content

ldb/lua-multipart-post

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multipart-post

Presentation

HTTP Multipart Post helper that does just that.

Dependencies

The module itself only depends on luasocket (for ltn12).

Tests require cwtest, a JSON parser and the availability of httpbin.org.

Usage

local mp = (require "multipart-post").gen_request
local H = (require "socket.http").request
local rq = mp{myfile = {name = "myfilename", data = "some data"}}
rq.url = "http://httpbin.org/post"
local b,c,h = H(rq)

See LuaSocket's http.request (generic interface) for more information.

If you only need to get the multipart/form-data body use encode:

local enc = (require "multipart-post").encode
local body, boundary = enc{foo="bar"}
-- use `boundary` to build the Content-Type header

Bugs

Non-ASCII part names and file names are not supported. According to RFC 2388:

Note that MIME headers are generally required to consist only of 7- bit data in the US-ASCII character set. Hence field names should be encoded according to the method in RFC 2047 if they contain characters outside of that set.

The sending application MAY supply a file name; if the file name of the sender's operating system is not in US-ASCII, the file name might be approximated, or encoded using the method of RFC 2231.

Copyright

  • Copyright (c) 2012-2013 Moodstocks SAS
  • Copyright (c) 2014-2016 Pierre Chapuis

About

HTTP Multipart Post helper that does just that.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Lua 88.4%
  • Makefile 11.6%