Я пытаюсь использовать wrk для генерации запроса https. Как передать запрос multipart / form-data в функцию wrk.format. Мой запрос выглядит как
Accept: application/json
Content-Type: multipart/form-data; boundary="----=_Part_0_140715475.1525373091109"
MIME-Version: 1.0
------=_Part_0_140715475.1525373091109
Content-Type: application/json; name=PersonName.json
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="PersonName"; filename="PersonName.json"
{
"Person":{
"Name":"test2",
"age":"23"
}
}
------=_Part_0_140715475.1525373091109--
ниже wrk_script в lua не работает, если я прочитал вышеуказанный блок запроса как переменную jsonBody в коде и передал в качестве аргумента body функцию wrk.format.
-- Load data from the file
function load_data_from_file(file)
lines = {}
-- Check if the file exists
local f=io.open(file,"r")
if f~=nil then
io.close(f)
else
-- Return the empty array
return lines
end
-- If the file exists loop through all its lines
-- and add them into the lines array
for line in io.lines(file) do
if not (line == '') then
for a, b in line:gmatch( "([^,]+),([^,]+)" ) do
lines[#lines + 1] = { person = a, jsonBody = b }
end
end
end
return lines
end
function init(args)
requests = 0
responses = 0
wrk.method = '_REQUESTMETHOD_'
wrk.body = '_REQUESTBODY_'
_HEAD_
end
-- Load data from file, here testdata.csv, should be in this directory
dataSets = load_data_from_file("testdata.csv")
if #dataSets == 0 then
print("Not a valid input data file. [testdata.csv]")
return
end
-- Initialize the dataSets array iterator
counter = 0
-- request handler
request = function()
counter = counter + 1
local req = nil
if dataSets[counter] ~= nil then
-- Get the next dataSets array element
url_path = "/person/" .. dataSets[counter].person .. "/names"
req = wrk.format(nil, url_path, nil, dataSets[counter].jsonBody )
end
-- If the counter is longer than the dataSets array length then reset it
if counter > #dataSets then
counter = 0
end
-- Return the request object with the current URL path
return req
end
-- response handler
response = function(status, headers, body)
end
ищу совет экспертов