From: Mikko Rasa Date: Thu, 22 Jan 2015 14:23:19 +0000 (+0200) Subject: Implement connection keep-alive in HttpServer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0165ed331051ae7fc64dfe85dd7ab8f5b11ba919;p=libs%2Fnet.git Implement connection keep-alive in HttpServer --- diff --git a/source/http/server.cpp b/source/http/server.cpp index b18ed4c..e0b34b3 100644 --- a/source/http/server.cpp +++ b/source/http/server.cpp @@ -121,8 +121,12 @@ void Server::client_data_available(Client &cl) cl.in_buf.erase(0, len); } + bool keepalive = false; if(cl.request && cl.request->is_complete() && !response) { + if(cl.request->has_header("Connection")) + keepalive = (cl.request->get_header("Connection")=="keep-alive"); + response = new Response(NONE); try { @@ -154,7 +158,18 @@ void Server::client_data_available(Client &cl) if(response) { cl.sock->write(response->str()); - cl.stale = true; + if(keepalive) + { + delete cl.request; + cl.request = 0; + delete cl.response; + cl.response = 0; + } + else + { + cl.sock->shutdown(IO::M_WRITE); + cl.stale = true; + } } }