Reverted removing the keep-alive and fixed a memory leak in server

This commit is contained in:
2025-02-08 12:25:21 -06:00
parent 27029586f4
commit 29c53b171d

View File

@ -545,6 +545,7 @@ namespace Tesses::Framework::Http
if(sock == nullptr) return; if(sock == nullptr) return;
Threading::Thread thrd2([sock,http,ip,port]()->void { Threading::Thread thrd2([sock,http,ip,port]()->void {
HttpServer::Process(*sock,*http,ip,port,false); HttpServer::Process(*sock,*http,ip,port,false);
delete sock;
}); });
thrd2.Detach(); thrd2.Detach();
} }
@ -834,6 +835,8 @@ namespace Tesses::Framework::Http
void HttpServer::Process(Stream& strm, IHttpServer& server, std::string ip, uint16_t port, bool encrypted) void HttpServer::Process(Stream& strm, IHttpServer& server, std::string ip, uint16_t port, bool encrypted)
{ {
while(true)
{
BufferedStream bStrm(strm); BufferedStream bStrm(strm);
StreamReader reader(bStrm); StreamReader reader(bStrm);
ServerContext ctx(&bStrm); ServerContext ctx(&bStrm);
@ -917,7 +920,19 @@ namespace Tesses::Framework::Http
if(ctx.version != "HTTP/1.1" ) return; if(ctx.version != "HTTP/1.1" ) return;
std::string connection;
if(ctx.requestHeaders.TryGetFirst("Connection", connection))
{
if(connection != "keep-alive") return;
}
if(ctx.responseHeaders.TryGetFirst("Connection", connection))
{
if(connection != "keep-alive") return;
}
if(bStrm.EndOfStream()) return;
}
} }
WebSocketConnection::~WebSocketConnection() WebSocketConnection::~WebSocketConnection()