in kong/kong/pdk/service/request.lua [495:566]
[CONTENT_TYPE_FORM_DATA] = function(args, mime)
local keys = {}
local boundary
local boundary_ok = false
local at = string_find(mime, "boundary=", 1, true)
if at then
at = at + 9
if string_byte(mime, at) == QUOTE then
local till = string_find(mime, '"', at + 1, true)
boundary = string_sub(mime, at + 1, till - 1)
else
boundary = string_sub(mime, at)
end
boundary_ok = true
end
repeat
if not boundary_ok then
boundary = tostring(math.random(1e10))
boundary_ok = true
end
local boundary_check = "\n--" .. boundary
local i = 1
for k, v in pairs(args) do
if type(k) ~= "string" then
error(("invalid key %q: got %s, " ..
"expected string"):format(k, type(k)), 3)
end
local tv = type(v)
if tv ~= "string" and tv ~= "number" and tv ~= "boolean" then
error(("invalid value %q: got %s, " ..
"expected string, number or boolean"):format(k, tv), 3)
end
keys[i] = k
i = i + 1
if string_find(tostring(v), boundary_check, 1, true) then
boundary_ok = false
end
end
until boundary_ok
table_sort(keys)
local out = {}
local i = 1
for _, k in ipairs(keys) do
out[i] = "--"
out[i + 1] = boundary
out[i + 2] = "\r\n"
out[i + 3] = 'Content-Disposition: form-data; name="'
out[i + 4] = k
out[i + 5] = '"\r\n\r\n'
local v = args[k]
out[i + 6] = v
out[i + 7] = "\r\n"
i = i + 8
end
out[i] = "--"
out[i + 1] = boundary
out[i + 2] = "--\r\n"
local output = table.concat(out)
return output, CONTENT_TYPE_FORM_DATA .. "; boundary=" .. boundary
end,