]> git.tdb.fi Git - libs/net.git/blobdiff - source/http/server.cpp
Provide more information about exceptions in Http::Server
[libs/net.git] / source / http / server.cpp
index 60d37c8f139b2b3ee3b344eb2220cbf89487b896..7caa0f5d025b6eb0e55db15f55cbf896aadf40ba 100644 (file)
@@ -1,6 +1,8 @@
 #include <exception>
+#include <typeinfo>
 #include <msp/core/maputils.h>
 #include <msp/core/refptr.h>
+#include <msp/debug/demangle.h>
 #include <msp/net/inet.h>
 #include <msp/net/resolve.h>
 #include <msp/net/streamsocket.h>
@@ -66,6 +68,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();
@@ -101,7 +108,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")
@@ -118,7 +125,8 @@ void Server::client_data_available(Client &cl)
                        catch(const exception &e)
                        {
                                response = new Response(BAD_REQUEST);
-                               response->add_content(e.what());
+                               response->add_content(format("An error occurred while parsing request headers:\ntype: %s\nwhat: %s",
+                                       Debug::demangle(typeid(e).name()), e.what()));
                        }
                        cl.in_buf = string();
                }
@@ -159,7 +167,8 @@ void Server::client_data_available(Client &cl)
                        responses.erase(cl.response);
                        cl.response = 0;
                        response = new Response(INTERNAL_ERROR);
-                       response->add_content(e.what());
+                       response->add_content(format("An error occurred while processing the request:\ntype: %s\nwhat: %s",
+                               Debug::demangle(typeid(e).name()), e.what()));
                }
        }