]> git.tdb.fi Git - libs/net.git/commitdiff
Adhere to the spec with connection keep-alive
authorMikko Rasa <tdb@tdb.fi>
Tue, 19 Apr 2016 07:38:57 +0000 (10:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 19 Apr 2016 07:53:27 +0000 (10:53 +0300)
Recognize it case-insensitively and add the header on the response.

source/http/server.cpp

index fbacb10accfc6a1de8c4497503c357aa457a16ac..60d37c8f139b2b3ee3b344eb2220cbf89487b896 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/net/resolve.h>
 #include <msp/net/streamsocket.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #include "request.h"
 #include "response.h"
 #include "server.h"
@@ -132,7 +133,7 @@ void Server::client_data_available(Client &cl)
        {
                cl.keepalive = false;
                if(cl.request->has_header("Connection"))
-                       cl.keepalive = (cl.request->get_header("Connection")=="keep-alive");
+                       cl.keepalive = !strcasecmp(cl.request->get_header("Connection"), "keep-alive");
 
                response = new Response(NONE);
                try
@@ -168,6 +169,8 @@ void Server::client_data_available(Client &cl)
 
 void Server::send_response(Client &cl, Response &resp)
 {
+       if(cl.keepalive)
+               resp.set_header("Connection", "keep-alive");
        cl.sock->write(resp.str());
        cl.async = false;
        if(cl.keepalive)