-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpost-random.lua
37 lines (33 loc) · 1.02 KB
/
post-random.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
-- init character set
local charset = {} do -- [0-9a-zA-Z]
for c = 48, 57 do table.insert(charset, string.char(c)) end
for c = 65, 90 do table.insert(charset, string.char(c)) end
for c = 97, 122 do table.insert(charset, string.char(c)) end
end
-- init random seed
math.randomseed(os.clock()^5)
-- returns a random string `length` long
local function randomString(length)
rs = ''
for i = 1, length do
rs = rs .. charset[math.random(1, #charset)]
end
return rs
end
-- Since generating random string is costly, try to
-- pregenerate 100 different payloads and just use
-- one of those
requests = {}
init = function()
for i=1, 100 do
requests[i] = randomString(2048)
end
end
-- this is the real code that runs for every request
request = function ()
wrk.method = "POST"
-- The body below is something to create a representative json. Not actual/relevant content
wrk.body = requests[math.random(1, #requests)]
wrk.headers["Content-Type"] = "application/txt"
return wrk.format("POST", "/")
end