aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2017-04-21 16:41:27 +0100
committerMatthew Wild <mwild1@gmail.com>2017-04-21 16:41:27 +0100
commit04d3816b69a847be365f41d5a625e224108b2c76 (patch)
tree4500189c661048668b5fcb2d70f139dee73d2f4a /net
parent279badc8aec122e4533560e2b34cf9021a8a75c4 (diff)
downloadprosody-04d3816b69a847be365f41d5a625e224108b2c76.tar.gz
prosody-04d3816b69a847be365f41d5a625e224108b2c76.zip
net.http: Allow creation of http client objects, with custom options
Diffstat (limited to 'net')
-rw-r--r--net/http.lua25
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;