diff options
Diffstat (limited to 'http_connection.cpp')
-rw-r--r-- | http_connection.cpp | 8 |
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))); +} |