aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-09-30 17:33:49 +0200
committerKim Alvefur <zash@zash.se>2021-09-30 17:33:49 +0200
commit08524a071e8160e8e4ca256f5c66bf09c98cfb61 (patch)
treef373c8b620f0c2a736cc45a50a3a62f76e88b17c /util
parentf5ea676b92a92fd720ad083d7e2a3b3a471545e7 (diff)
downloadprosody-08524a071e8160e8e4ca256f5c66bf09c98cfb61.tar.gz
prosody-08524a071e8160e8e4ca256f5c66bf09c98cfb61.zip
prosodyctl: Use HTTP client in promise mode for connectivity check
Feels a bit cleaner to hide away the async.waiter() and return value handling. Also line count reduction!
Diffstat (limited to 'util')
-rw-r--r--util/prosodyctl/check.lua40
1 files changed, 14 insertions, 26 deletions
diff --git a/util/prosodyctl/check.lua b/util/prosodyctl/check.lua
index cac96cd4..fe516041 100644
--- a/util/prosodyctl/check.lua
+++ b/util/prosodyctl/check.lua
@@ -7,42 +7,30 @@ local socket = require "socket";
local jid_split = require "util.jid".prepped_split;
local modulemanager = require "core.modulemanager";
-local function check_api(check_type, target_host)
- local async = require "util.async";
- local wait, done = async.waiter();
+local function check_ojn(check_type, target_host)
local http = require "net.http"; -- .new({});
local urlencode = require "util.http".urlencode;
local json = require "util.json";
- local ok = false;
- local err = nil;
- local decoded_body = nil;
-
- http.request(
+ local response, err = async.wait_for(http.request(
("https://observe.jabber.network/api/v1/check/%s"):format(urlencode(check_type)),
{
method="POST",
headers={["Accept"] = "application/json"; ["Content-Type"] = "application/json"},
body=json.encode({target=target_host}),
- },
- function (body, code)
- if code ~= 200 then
- err = ("API replied with non-200 code: %d"):format(code)
- else
- decoded_body, err = json.decode(body);
- if decoded_body == nil then
- err = ("Failed to parse API JSON: %s"):format(err)
- else
- ok = true
- end
- end
- done();
- end
- );
- wait();
+ }));
- if not ok then
- return false, err
+ if not response then
+ return false, err;
+ end
+
+ if response.code ~= 200 then
+ return false, ("API replied with non-200 code: %d"):format(response.code);
+ end
+
+ local decoded_body, err = json.decode(response.body);
+ if decoded_body == nil then
+ return false, ("Failed to parse API JSON: %s"):format(err)
end
local success = decoded_body["success"];