net.http: Set Connection header based on connection pool usage

Connection: keep-alive is implicit in HTTP/1.1 but explicit > implicit
This commit is contained in:
Kim Alvefur 2023-11-11 23:48:45 +01:00
parent 8e2ecac95b
commit 019549e738

View file

@ -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