Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 1 | core.register_service("set_var", "http", function(applet) |
| 2 | local var_name = applet.headers["var"][0] |
| 3 | local result = applet:set_var(var_name, "value") |
| 4 | if result then |
| 5 | applet:set_status(202) |
| 6 | else |
| 7 | applet:set_status(400) |
| 8 | end |
| 9 | applet:add_header("echo", applet:get_var(var_name) or "(nil)") |
| 10 | applet:start_response() |
| 11 | applet:send("") |
| 12 | end) |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 13 | |
| 14 | core.register_service("set_var_ifexist", "http", function(applet) |
| 15 | local var_name = applet.headers["var"][0] |
| 16 | local result = applet:set_var(var_name, "value", true) |
| 17 | if result then |
| 18 | applet:set_status(202) |
| 19 | else |
| 20 | applet:set_status(400) |
| 21 | end |
| 22 | applet:add_header("echo", applet:get_var(var_name) or "(nil)") |
| 23 | applet:start_response() |
| 24 | applet:send("") |
| 25 | end) |