Mercurial > prosody-modules
comparison mod_auth_http_async/mod_auth_http_async.lua @ 2811:39156d6f7268
mod_auth_http_async: Allow LuaSocket to pollute the global scope (fixes #1033)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 31 Oct 2017 19:31:54 +0100 |
parents | 1d139e33c502 |
children |
comparison
equal
deleted
inserted
replaced
2810:9a3e51f348fe | 2811:39156d6f7268 |
---|---|
24 rawset(_G, "PROXY", false) | 24 rawset(_G, "PROXY", false) |
25 end | 25 end |
26 if rawget(_G, "base_parsed") == nil then | 26 if rawget(_G, "base_parsed") == nil then |
27 rawset(_G, "base_parsed", false) | 27 rawset(_G, "base_parsed", false) |
28 end | 28 end |
29 if not have_async then -- FINE! Set your globals then | |
30 prosody.unlock_globals() | |
31 require "ltn12" | |
32 require "socket" | |
33 require "socket.http" | |
34 require "ssl.https" | |
35 prosody.lock_globals() | |
36 end | |
29 | 37 |
30 local function async_http_auth(url, username, password) | 38 local function async_http_auth(url, username, password) |
31 module:log("debug", "async_http_auth()"); | 39 module:log("debug", "async_http_auth()"); |
32 local http = require "net.http"; | 40 local http = require "net.http"; |
33 local wait, done = async.waiter(); | 41 local wait, done = async.waiter(); |
34 local content, code, request, response; | 42 local content, code, request, response; |
35 local ex = { | 43 local ex = { |
36 headers = { Authorization = "Basic "..base64(username..":"..password); }; | 44 headers = { Authorization = "Basic "..base64(username..":"..password); }; |
49 end | 57 end |
50 return nil, "Auth failed. Invalid username or password."; | 58 return nil, "Auth failed. Invalid username or password."; |
51 end | 59 end |
52 | 60 |
53 local function sync_http_auth(url,username, password) | 61 local function sync_http_auth(url,username, password) |
54 module:log("debug", "sync_http_auth()"); | 62 module:log("debug", "sync_http_auth()"); |
63 require "ltn12"; | |
55 local http = require "socket.http"; | 64 local http = require "socket.http"; |
56 local https = require "ssl.https"; | 65 local https = require "ssl.https"; |
57 local request; | 66 local request; |
58 if string.sub(url, 1, string.len('https')) == 'https' then | 67 if string.sub(url, 1, string.len('https')) == 'https' then |
59 request = https.request; | 68 request = https.request; |