Mercurial > prosody-modules
comparison mod_s2s_auth_monkeysphere/mod_s2s_auth_monkeysphere.lua @ 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 | cfe360d9d82c |
children | 8d1141025b43 |
comparison
equal
deleted
inserted
replaced
2185:2cbd7876ba14 | 2186:a100f4a720cb |
---|---|
4 local ltn12 = require"ltn12"; | 4 local ltn12 = require"ltn12"; |
5 local json = require"util.json"; | 5 local json = require"util.json"; |
6 local json_encode, json_decode = json.encode, json.decode; | 6 local json_encode, json_decode = json.encode, json.decode; |
7 local gettime = require"socket".gettime; | 7 local gettime = require"socket".gettime; |
8 local serialize = require"util.serialization".serialize; | 8 local serialize = require"util.serialization".serialize; |
9 local have_async, async = pcall(require, "util.async"); | |
9 | 10 |
10 local msva_url = assert(os.getenv"MONKEYSPHERE_VALIDATION_AGENT_SOCKET", | 11 local msva_url = assert(os.getenv"MONKEYSPHERE_VALIDATION_AGENT_SOCKET", |
11 "MONKEYSPHERE_VALIDATION_AGENT_SOCKET is unset, please set it").."/reviewcert"; | 12 "MONKEYSPHERE_VALIDATION_AGENT_SOCKET is unset, please set it").."/reviewcert"; |
13 | |
14 if have_async then | |
15 local _http_request = require "net.http".request; | |
16 function http_request(url, ex) | |
17 local wait, done = async.waiter(); | |
18 local content, code, request, response; | |
19 _http_request(url, ex, function (_content, _code, _request, _response) | |
20 content, code, request, response = _content, _code, _request, _response; | |
21 done(); | |
22 end); | |
23 wait(); | |
24 return content, code, request, response; | |
25 end | |
26 end | |
12 | 27 |
13 local function check_with_monkeysphere(event) | 28 local function check_with_monkeysphere(event) |
14 local session, host, cert = event.session, event.host, event.cert; | 29 local session, host, cert = event.session, event.host, event.cert; |
15 local result = {}; | 30 local result = {}; |
16 local post_body = json_encode { | 31 local post_body = json_encode { |