-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.lua
60 lines (49 loc) · 1.36 KB
/
example.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
--[[
The script itself is only executed once.
You can use global variables which will be shared between all requests.
]]--
local counter = 0
--[[
The request function is called each time a request is constructed.
Arguments:
0: A per worker state table that can be used to keep a state between the
request and response function.
Return value:
An object containing the request that should be performed.
]]--
function request(state)
counter = counter + 1
return {
['method' ] = 'GET',
['url' ] = 'http://127.0.0.1:9090/',
['headers'] = {
['User-Agent'] = 'hench example',
['X-Foo'] = counter
}
}
end
--[[
The response function is called each time after a response is returned.
Arguments:
0: An object containing the response.
For example:
{
['status'] = 200,
['body'] = 'test',
['headers'] = {
['X-Foo'] = {
'bar',
'baz'
},
['Connection'] = 'keep-alive'
}
}
1: A per worker state table that can be used to keep a state between the
request and response function.
Return value:
Whether the request was a success or not. Returning anything other than
true will increase the error counter.
]]--
function response(res, state)
return res.status == 200
end