diff --git a/Makefile b/Makefile index 06f8fa1..dbf07b0 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ PREFIX?=$(HOME) -BOOST_INCLUDE?=/opt/local/include -BOOST_LIB?=/opt/local/lib +BOOST_INCLUDE?=$(HOME)/dev/boost_1_72_0 +BOOST_LIB?=$(HOME)/dev/boost_1_72_0/stage/lib SIGNING_IDENTITY?=68AD28395D8090C2A8ACDD3A31FA6735C8DAE2F4 @@ -12,7 +12,7 @@ CC?=cc CXX?=c++ CFLAGS+=-std=c11 CXXFLAGS+=-I$(BOOST_INCLUDE) -std=c++11 -LDFLAGS+=-L$(BOOST_LIB) -lboost_regex-mt +LDFLAGS+=-L$(BOOST_LIB) -lboost_regex -lboost_filesystem ifdef NDEBUG CFLAGS+=-O3 -DNDEBUG diff --git a/htdocs/test.html b/htdocs/test.html index 46af4b9..e0ae57e 100644 --- a/htdocs/test.html +++ b/htdocs/test.html @@ -1,5 +1,8 @@ + + pEp::Webserver running. + - This is a test page. + This is the test page of the p≡p Webserver. If you can see this then everything works. diff --git a/test_webserver.cc b/test_webserver.cc index a250329..84d5d4c 100644 --- a/test_webserver.cc +++ b/test_webserver.cc @@ -1,9 +1,12 @@ #include +#include + #include "webserver.hh" int main() { pEp::Webserver web{net::ip::address::from_string("127.0.0.1"), 8080, "htdocs"}; + web.run(); return 0; } diff --git a/webserver.cc b/webserver.cc index e69f042..028f8a5 100644 --- a/webserver.cc +++ b/webserver.cc @@ -16,7 +16,7 @@ namespace pEp { Webserver::Webserver(net::ip::address addr, unsigned short port, std::string doc_root) : _ioc(1), _acceptor(_ioc, {addr, port}), _doc_root(doc_root), _running(false) { } -static beast::string_view mime_type(beast::string_view path) +beast::string_view Webserver::mime_type(beast::string_view path) { using beast::iequals; auto const ext = [&path] @@ -45,11 +45,6 @@ static beast::string_view mime_type(beast::string_view path) return "application/octet-stream"; } -static void fail(beast::error_code ec, char const* what) -{ - std::cerr << what << ": " << ec.message() << "\n"; -;} - void Webserver::add_url_handler(std::string url_regex, handler_t handler) { std::lock_guard< std::mutex > lock(_mtx); @@ -81,9 +76,10 @@ void Webserver::deliver_file(tcp::socket *socket, Webserver::request req) static boost::regex file{"/([\\w\\d]{1,100}\\.[\\w\\d]{1,4})"}; boost::cmatch m; // there's a strange bug without this string variable d - // req.target().data() may end with '\x10' when directly being put into - // regex_match() + // req.target().data() may end with '\x10' std::string d = req.target().data(); + if (d.back() == '\x10') + d.pop_back(); if (boost::regex_match(d.c_str(), m, file)) { fs::path p{_doc_root}; p /= m[1]; @@ -139,7 +135,7 @@ void Webserver::do_session(tcp::socket *socket) break; if (ec) { delete socket; - return fail(ec, "reading from stream"); + throw std::ios_base::failure(ec.message()); } switch (req.method()) { @@ -173,7 +169,7 @@ void Webserver::do_session(tcp::socket *socket) if (ec) { delete socket; - return fail(ec, "writing to stream"); + throw std::ios_base::failure(ec.message()); } } diff --git a/webserver.hh b/webserver.hh index b6d12f8..fab5f13 100644 --- a/webserver.hh +++ b/webserver.hh @@ -55,6 +55,8 @@ namespace pEp { void run(); void shutdown(); + static beast::string_view mime_type(beast::string_view path); + protected: void deliver_status(tcp::socket *socket, request req, http::status status); void deliver_file(tcp::socket *socket, request req);