From 75bfec7731e0d42ad5733a62b9772db9c72aeef9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 30 Jul 2019 02:35:17 +0200 Subject: net.*: Remove tostring call from logging Taken care of by loggingmanager now --- net/http.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index fe5250ac..0e03fb3a 100644 --- a/net/http.lua +++ b/net/http.lua @@ -40,7 +40,7 @@ local listener = { default_port = 80, default_mode = "*a" }; local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); return err; end local function log_if_failed(req, ret, ...) if not ret then - log("error", "Request '%s': error in callback: %s", req.id, tostring((...))); + log("error", "Request '%s': error in callback: %s", req.id, (...)); if not req.suppress_errors then error(...); end @@ -150,7 +150,7 @@ function listener.onincoming(conn, data) local request = requests[conn]; if not request then - log("warn", "Received response from connection %s with no request attached!", tostring(conn)); + log("warn", "Received response from connection %s with no request attached!", conn); return; end -- cgit v1.2.3 From 92b963270a4e399096f66ac9353a99574915d2e7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 1 Sep 2019 02:05:33 +0200 Subject: net.http: Pass server name along for SNI (fixes #1408) net.resolver.basic passes this 'extra' field along to server.addclient --- net/http.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index 0e03fb3a..055fc936 100644 --- a/net/http.lua +++ b/net/http.lua @@ -260,7 +260,7 @@ local function request(self, u, ex, callback) sslctx = ex and ex.sslctx or self.options and self.options.sslctx; end - local http_service = basic_resolver.new(host, port_number); + local http_service = basic_resolver.new(host, port_number, "tcp", { servername = req.host }); connect(http_service, listener, { sslctx = sslctx }, req); self.events.fire_event("request", { http = self, request = req, url = u }); -- cgit v1.2.3 From e354f1abd8ca2fb0fc2c25c1c61c1866cc41d5eb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 29 Nov 2019 23:25:59 +0100 Subject: net.http: Set ALPN on requests Shouldn't hurt. Revert if it turns out it does. Supported in LuaSec 0.8. Should be ignored otherwise. --- net/http.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index 055fc936..8ca30db2 100644 --- a/net/http.lua +++ b/net/http.lua @@ -285,7 +285,7 @@ local function new(options) end local default_http = new({ - sslctx = { mode = "client", protocol = "sslv23", options = { "no_sslv2", "no_sslv3" } }; + sslctx = { mode = "client", protocol = "sslv23", options = { "no_sslv2", "no_sslv3" }, alpn = "http/1.1" }; suppress_errors = true; }); -- cgit v1.2.3 From 7d924c49ac817353980f9505ed83845ce0b8377c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 6 May 2020 18:03:20 +0200 Subject: net.http: Return a Promise if no callback is given --- net/http.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index 8ca30db2..5fbed4fe 100644 --- a/net/http.lua +++ b/net/http.lua @@ -12,6 +12,8 @@ local httpstream_new = require "net.http.parser".new; local util_http = require "util.http"; local events = require "util.events"; local verify_identity = require"util.x509".verify_identity; +local promise = require "util.promise"; +local errors = require "util.error"; local basic_resolver = require "net.resolvers.basic"; local connect = require "net.connect".connect; @@ -270,7 +272,21 @@ end local function new(options) local http = { options = options; - request = request; + request = function (self, u, ex, callback) + if callback ~= nil then + return request(self, u, ex, callback); + else + return promise.new(function (resolve, reject) + request(self, u, ex, function (body, code, a, b) + if code == 0 then + reject(errors.new(body, { request = a })); + else + resolve({ request = b, response = a }); + end + end); + end); + end + end; new = options and function (new_options) local final_options = {}; for k, v in pairs(options) do final_options[k] = v; end -- cgit v1.2.3 From 209660f21244ee06b5bfcd8f5addc830058d3104 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 25 Aug 2020 15:57:39 +0100 Subject: net.http: use new net.http.errors lib for creating error object --- net/http.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index f1055840..2deeae14 100644 --- a/net/http.lua +++ b/net/http.lua @@ -13,7 +13,7 @@ local util_http = require "util.http"; local events = require "util.events"; local verify_identity = require"util.x509".verify_identity; local promise = require "util.promise"; -local errors = require "util.error"; +local http_errors = require "net.http.errors"; local basic_resolver = require "net.resolvers.basic"; local connect = require "net.connect".connect; @@ -291,7 +291,7 @@ local function new(options) return promise.new(function (resolve, reject) request(self, u, ex, function (body, code, a, b) if code == 0 then - reject(errors.new(body, { request = a })); + reject(http_errors.new(body, { request = a })); else resolve({ request = b, response = a }); end -- cgit v1.2.3 From c340e3ab373d32fd909e5902538031ed30d9585f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 25 Aug 2020 15:59:04 +0100 Subject: net.http: http.request() promise now resolves with response (breaking change) Promise mode is not (widely?) used, changing this now while we can, as it improves usability of the API. The request is now available as response.request, if needed. --- net/http.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index 2deeae14..c417ebec 100644 --- a/net/http.lua +++ b/net/http.lua @@ -293,7 +293,8 @@ local function new(options) if code == 0 then reject(http_errors.new(body, { request = a })); else - resolve({ request = b, response = a }); + a.request = b; + resolve(a); end end); end); -- cgit v1.2.3 From b50d4b2ef0a476f282e5413e65e8b7ed17f1dd4b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 21 Oct 2020 10:40:11 +0100 Subject: net.http: Add support for streaming chunked/large responses --- net/http.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index 31157afa..bb247d18 100644 --- a/net/http.lua +++ b/net/http.lua @@ -83,7 +83,24 @@ local function request_reader(request, data, err) return; end + local finalize_sink; local function success_cb(r) + if r.partial then + -- Request should be streamed + log("debug", "Request '%s': partial response (%s%s)", + request.id, + r.chunked and "chunked, " or "", + r.body_length and ("%d bytes"):format(r.body_length) or "unknown length" + ); + if request.streaming_handler then + log("debug", "Request '%s': Streaming via handler"); + r.body_sink, finalize_sink = request.streaming_handler(r); + end + return; + elseif finalize_sink then + log("debug", "Request '%s': Finalizing response stream"); + finalize_sink(r); + end if request.callback then request.callback(r.body, r.code, r, request); request.callback = nil; @@ -256,6 +273,7 @@ local function request(self, u, ex, callback) end req.insecure = ex.insecure; req.suppress_errors = ex.suppress_errors; + req.streaming_handler = ex.streaming_handler; end log("debug", "Making %s %s request '%s' to %s", req.scheme:upper(), method or "GET", req.id, (ex and ex.suppress_url and host_header) or u); -- cgit v1.2.3