-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathshutdown.lua
More file actions
47 lines (37 loc) · 1.51 KB
/
shutdown.lua
File metadata and controls
47 lines (37 loc) · 1.51 KB
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
-- Example to shutdown client or origin connection
-- This is done with a request header 'choice'
-- e.g. with an entry in remap.config like below and a test file 'test.txt' with random texts inside
-- map http://test.com/ http://httpbin.org/
-- curl -v -H'choice: cut_server' -H 'Host: test.com' -d "@test.txt" -X POST 'http://localhost:8080/post'
-- this will shutdown connection with the origin. It will also trigger the ATS to do retries if it is setup to do so. And after that, a status 502 will be returned to client
-- curl -v -H'choice: cut_client' -H 'Host: test.com' -d "@test.txt" -X POST 'http://localhost:8080/post'
-- this will shutdown connection with the client. It will cause the client to lose connection with ATS
-- reference for shutdown call
-- https://www.man7.org/linux/man-pages/man2/shutdown.2.html
local ffi = require 'ffi'
ffi.cdef[[
int shutdown(int, int);
]]
local glibc = ffi.C
function transform(data, eos)
ts.debug("testing")
ts.debug(data)
end
function do_global_send_request()
ts.debug("start sending request")
local choice = ts.client_request.header['choice']
if (choice == 'cut_server') then
local fd = ts.http.get_server_fd()
ts.debug('fd: ' .. fd)
glibc.shutdown(fd, 1)
end
if (choice == 'cut_client') then
local fd = ts.http.get_client_fd()
ts.debug('fd: ' .. fd)
glibc.shutdown(fd, 1)
end
ts.debug("done with sending request")
end
function do_global_read_request()
ts.hook(TS_LUA_REQUEST_CLIENT, transform)
end