summaryrefslogtreecommitdiff
path: root/http_connection.cpp
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-12-29 22:08:06 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-12-29 22:08:06 +0100
commit5d94fe647e59aaec7775f1e1bd4a4982b677af01 (patch)
treee459388b0d937bdb4034676c1a8276c59904fc68 /http_connection.cpp
parent2133fd579e0d4726b032288d10d053231109c586 (diff)
HTTPServer/HTTPConnection cleanup.
Diffstat (limited to 'http_connection.cpp')
-rw-r--r--http_connection.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/http_connection.cpp b/http_connection.cpp
new file mode 100644
index 0000000..36c0f00
--- /dev/null
+++ b/http_connection.cpp
@@ -0,0 +1,38 @@
+#include "http_connection.h"
+
+#include "http.h"
+#include "music.h"
+
+#include <boost/bind.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+
+HTTP::Connection::Connection(boost::asio::io_service& io_service) : socket(io_service) {
+}
+
+void HTTP::Connection::handle_write(const boost::system::error_code& error, size_t bytes_transferred) {
+}
+
+void HTTP::Connection::handle_read(const boost::system::error_code& error, size_t bytes_transferred) {
+ std::istream is(&buf);
+ HTTPRequest req(is);
+
+ HTTPResponse res(socket);
+
+ MusicListing::p ml = music::get(req.path);
+ if(ml) {
+ res.code = 200;
+ res.status = "OK";
+
+ ml->render(req, res);
+ } else {
+ res.code = 404;
+ res.status = "Not Found";
+ }
+}
+
+void HTTP::Connection::start() {
+ boost::asio::async_read_until(socket, buf, "\r\n\r\n", boost::bind(&Connection::handle_read, shared_from_this(),
+ boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
+}