summaryrefslogtreecommitdiff
path: root/httpd.cpp
diff options
context:
space:
mode:
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.
+ }
+}