summaryrefslogtreecommitdiff
path: root/http_connection.cpp
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-01-02 21:45:20 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-01-02 21:45:46 +0100
commitb72175dab679c14be80b6e5db7129f8d3b518079 (patch)
tree88d82aaed69f83c0fa68a2831a029527eea4a413 /http_connection.cpp
parentb53ea34b123721f70ae6e4ff4eb96e90e0664ba4 (diff)
Add HTTP::Connection::send_error.
Diffstat (limited to 'http_connection.cpp')
-rw-r--r--http_connection.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/http_connection.cpp b/http_connection.cpp
index 6567f81..a86d2ac 100644
--- a/http_connection.cpp
+++ b/http_connection.cpp
@@ -3,6 +3,7 @@
#include "http.h"
#include <boost/bind.hpp>
+#include <boost/format.hpp>
HTTP::Connection::Connection(boost::asio::io_service& io_service) : socket(io_service) {
}
@@ -14,7 +15,8 @@ void HTTP::Connection::handle_read(const boost::system::error_code& error, size_
if(!parse_request(buf)) {
// Request parse error.
std::cout << "Request parse error." << std::endl;
- //return;
+ send_error(400, "Bad Request");
+ return;
}
std::cout << "Path: " << std::endl;
@@ -54,3 +56,7 @@ std::string HTTP::Connection::pop_path_base() {
return base_path.back();
}
+
+void HTTP::Connection::send_error(int code, std::string name) {
+ boost::asio::write(socket, boost::asio::buffer(boost::str(boost::format("HTTP/1.1 %1$d %2$s\r\n\r\n<h1>%1$d %2$s</h1>") % code % name)));
+}