]> git.tdb.fi Git - libs/net.git/blobdiff - source/http/server.cpp
Use string::size_type to store string offsets
[libs/net.git] / source / http / server.cpp
index fbacb10accfc6a1de8c4497503c357aa457a16ac..f0474fd18e993c57de16b1a3f51c07dc260f069f 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"
@@ -65,6 +66,11 @@ void Server::submit_response(Response &resp)
                send_response(cl, *cl.response);
 }
 
+void Server::cancel_keepalive(Response &resp)
+{
+       get_client_by_response(resp).keepalive = false;
+}
+
 void Server::data_available()
 {
        Net::StreamSocket *csock = sock.accept();
@@ -100,7 +106,7 @@ void Server::client_data_available(Client &cl)
                                cl.request = new Request(Request::parse(cl.in_buf));
 
                                string addr_str = cl.sock->get_peer_address().str();
-                               unsigned colon = addr_str.find(':');
+                               string::size_type colon = addr_str.find(':');
                                cl.request->set_header("-Client-Host", addr_str.substr(0, colon));
 
                                if(cl.request->get_method()!="GET" && cl.request->get_method()!="POST")
@@ -132,7 +138,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 +174,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)