diff options
author | Matthew Wild <mwild1@gmail.com> | 2017-04-21 16:41:27 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2017-04-21 16:41:27 +0100 |
commit | 527e6d6086ee82b15e50564dda5249aa9734ce49 (patch) | |
tree | 4500189c661048668b5fcb2d70f139dee73d2f4a /net/http.lua | |
parent | db408d9cf0fbec0bc273ceaf23c80e53dddcd95d (diff) | |
download | prosody-527e6d6086ee82b15e50564dda5249aa9734ce49.tar.gz prosody-527e6d6086ee82b15e50564dda5249aa9734ce49.zip |
net.http: Allow creation of http client objects, with custom options
Diffstat (limited to 'net/http.lua')
-rw-r--r-- | net/http.lua | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/net/http.lua b/net/http.lua index 2fd46db9..986b6dc4 100644 --- a/net/http.lua +++ b/net/http.lua @@ -10,6 +10,7 @@ local b64 = require "util.encodings".base64.encode; local url = require "socket.url" local httpstream_new = require "net.http.parser".new; local util_http = require "util.http"; +local events = require "util.events"; local ssl_available = pcall(require, "ssl"); @@ -122,7 +123,7 @@ local function log_if_failed(id, ret, ...) return ...; end -local function request(u, ex, callback) +local function request(self, u, ex, callback) local req = url.parse(u); if not (req and req.host) then @@ -207,9 +208,27 @@ local function request(u, ex, callback) return req; end -return { - request = request; +local function new(options) + local http = { + options = options; + request = request; + new = options and function (new_options) + return new(setmetatable(new_options, { __index = options })); + end or new; + events = events.new(); + request = request; + }; + return http; +end +local default_http = new(); + +return { + request = function (u, ex, callback) + return default_http:request(u, ex, callback); + end; + new = new; + events = default_http.events; -- COMPAT urlencode = util_http.urlencode; urldecode = util_http.urldecode; |