-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipart.lua
38 lines (31 loc) · 958 Bytes
/
multipart.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
local CRLF = "\r\n"
function announce.multipart()
local parts = {}
local boundary = "" .. (math.random() * 10000)
return {
add = function(name, data)
table.insert(parts, {
name = name,
data = data
})
end,
boundary = function()
return boundary
end,
contentType = function()
return "multipart/form-data; boundary=" .. boundary
end,
serialize = function()
local str = ""
for _, part in ipairs(parts) do
str = str .. "--" .. boundary .. CRLF
str = str .. "Content-Disposition: form-data; name=\"" .. part.name .. "\"" .. CRLF
str = str .. CRLF
str = str .. part.data
str = str .. CRLF
end
str = str .. "--" .. boundary .. "--" .. CRLF
return str
end
}
end