changeset 2186:a100f4a720cb

mod_s2s_auth_monkeysphere: Query Monkeysphere asynchronously if util.async is available
author Kim Alvefur <zash@zash.se>
date Mon, 30 May 2016 16:44:31 +0200
parents 2cbd7876ba14
children 287f37e6b6e1
files mod_s2s_auth_monkeysphere/mod_s2s_auth_monkeysphere.lua
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_s2s_auth_monkeysphere/mod_s2s_auth_monkeysphere.lua	Sat May 28 16:55:43 2016 +0200
+++ b/mod_s2s_auth_monkeysphere/mod_s2s_auth_monkeysphere.lua	Mon May 30 16:44:31 2016 +0200
@@ -6,10 +6,25 @@
 local json_encode, json_decode = json.encode, json.decode;
 local gettime = require"socket".gettime;
 local serialize = require"util.serialization".serialize;
+local have_async, async = pcall(require, "util.async");
 
 local msva_url = assert(os.getenv"MONKEYSPHERE_VALIDATION_AGENT_SOCKET",
 	"MONKEYSPHERE_VALIDATION_AGENT_SOCKET is unset, please set it").."/reviewcert";
 
+if have_async then
+	local _http_request = require "net.http".request;
+	function http_request(url, ex)
+		local wait, done = async.waiter();
+		local content, code, request, response;
+		_http_request(url, ex, function (_content, _code, _request, _response)
+			content, code, request, response = _content, _code, _request, _response;
+			done();
+		end);
+		wait();
+		return content, code, request, response;
+	end
+end
+
 local function check_with_monkeysphere(event)
 	local session, host, cert = event.session, event.host, event.cert;
 	local result = {};