-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcbor_test.lua
More file actions
26 lines (20 loc) · 735 Bytes
/
cbor_test.lua
File metadata and controls
26 lines (20 loc) · 735 Bytes
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
-- lua_cbor (Verison 1.0.0-1) is used - https://www.zash.se/lua-cbor.html
-- This is a pure lua implementation (almost) without external dependency
-- Place cbor.lua in a directory with other lua files. e.g. /usr/local/trafficserver/etc/trafficserver/
ts.add_package_path('/usr/local/trafficserver/etc/trafficserver/?.lua')
local cbor = require "cbor";
function do_global_send_response()
-- Encode a Lua table to CBOR
local data_to_encode = {
name = "Alice",
age = 30,
is_active = true,
hobbies = {"reading", "hiking"},
address = {
street = "123 Main St",
city = "Anytown"
}
}
local encoded_cbor = cbor.encode(data_to_encode)
ts.client_response.header['test'] = encoded_cbor
end