summaryrefslogtreecommitdiff
path: root/httpd.cpp
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-01-02 16:13:15 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-01-02 16:13:15 +0100
commit4a0d339854536f65b9418c79b617bb718062905f (patch)
treec7b80fee61114197269beb37af7dc345c81336db /httpd.cpp
parent1ec379a805fdc4e7e076f1f59fa054bde8cf89c2 (diff)
Decoupled HTTP::Connection from handler.
Diffstat (limited to 'httpd.cpp')
-rw-r--r--httpd.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/httpd.cpp b/httpd.cpp
index d67533d..e2470c2 100644
--- a/httpd.cpp
+++ b/httpd.cpp
@@ -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.
+ }
+}