diff options
Diffstat (limited to 'httpd.cpp')
-rw-r--r-- | httpd.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -17,7 +17,26 @@ void HTTP::Server::start_accept() { void HTTP::Server::handle_accept(Connection::p new_connection, const boost::system::error_code& error) { if(!error) { - new_connection->start(); + new_connection->read_request(boost::bind(&Server::handle_request, this, _1)); start_accept(); } } + +void HTTP::Server::handle_request(Connection::p connection) { + std::string handler; + + if(connection->path.size()) { + // Pop first element of path. + handler = connection->path.front(); + connection->path.erase(connection->path.begin()); + } else { + handler = "index"; + } + + if(handlers.count(handler)) { + // Call handler. + handlers[handler](connection); + } else { + // Error 404. + } +} |