diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-02 16:13:15 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-02 16:13:15 +0100 |
commit | 4a0d339854536f65b9418c79b617bb718062905f (patch) | |
tree | c7b80fee61114197269beb37af7dc345c81336db /httpd.cpp | |
parent | 1ec379a805fdc4e7e076f1f59fa054bde8cf89c2 (diff) |
Decoupled HTTP::Connection from handler.
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. + } +} |