From 019549e7381ef1524bbb6550eb0140661ae3d4a5 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 11 Nov 2023 23:48:45 +0100 Subject: net.http: Set Connection header based on connection pool usage Connection: keep-alive is implicit in HTTP/1.1 but explicit > implicit --- net/http.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/http.lua b/net/http.lua index 2685b491..bea1e905 100644 --- a/net/http.lua +++ b/net/http.lua @@ -115,7 +115,8 @@ local function request_reader(request, data, err) request.callback(r.body, r.code, r, request); request.callback = nil; end - destroy_request(request); + local persistent = (","..(r.headers.connection or "keep-alive")..","):find(",keep-alive,") + destroy_request(request, persistent); end local function options_cb() return request; @@ -269,6 +270,12 @@ local function request(self, u, ex, callback) ["User-Agent"] = "Prosody XMPP Server"; }; + if self.pool then + headers["Connection"] = "keep-alive"; + else + headers["Connection"] = "close"; + end + if req.userinfo then headers["Authorization"] = "Basic "..b64(req.userinfo); end -- cgit v1.2.3