]> git.tdb.fi Git - libs/net.git/commitdiff
Implement connection keep-alive in HttpServer
authorMikko Rasa <tdb@tdb.fi>
Thu, 22 Jan 2015 14:23:19 +0000 (16:23 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 22 Jan 2015 14:23:19 +0000 (16:23 +0200)
source/http/server.cpp

index b18ed4c76b02dec85572e41cfecac26f2f186852..e0b34b382e8a9d86e0a9c0a862a2a9250fa2220a 100644 (file)
@@ -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;
+               }
        }
 }