X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhttp%2Fserver.cpp;h=ed3a2b9288339830ee89f0b56585960ddb24d398;hb=5f6c5ae5527619f7ffc82a69cf73d3fc7347e51f;hp=47de7dd381b6c84cd995e4dd56239ab64d91b2e2;hpb=b884825f8415c3bd300c433e1e155d98dbc56550;p=libs%2Fnet.git diff --git a/source/http/server.cpp b/source/http/server.cpp index 47de7dd..ed3a2b9 100644 --- a/source/http/server.cpp +++ b/source/http/server.cpp @@ -84,6 +84,8 @@ void Server::client_data_available(Client &cl) char rbuf[4096]; unsigned len = cl.sock->read(rbuf, sizeof(rbuf)); + if(cl.stale) + return; cl.in_buf.append(rbuf, len); RefPtr response; @@ -104,6 +106,11 @@ void Server::client_data_available(Client &cl) response = new Response(NOT_IMPLEMENTED); response->add_content("Method not implemented\n"); } + else if(cl.request->get_path()[0]!='/') + { + response = new Response(BAD_REQUEST); + response->add_content("Path must be absolute\n"); + } } catch(const exception &e) { @@ -119,8 +126,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 { @@ -152,7 +163,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; + } } }