Browse Source

...

pull/1/head
Volker Birk 2 years ago
parent
commit
2e7f867c30
1 changed files with 14 additions and 10 deletions
  1. +14
    -10
      webserver.cc

+ 14
- 10
webserver.cc View File

@ -1,20 +1,14 @@
// this file is derived from a boost::beast sample
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/config.hpp>
#include <boost/filesystem/path.hpp>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace fs = boost::filesystem;
#include "webserver.hh"
@ -48,7 +42,7 @@ static beast::string_view mime_type(beast::string_view path)
if(iequals(ext, ".tif")) return "image/tiff";
if(iequals(ext, ".svg")) return "image/svg+xml";
if(iequals(ext, ".svgz")) return "image/svg+xml";
return "application/octet-stream";
return "";
}
static void fail(beast::error_code ec, char const* what)
@ -69,11 +63,21 @@ void Webserver::remove_url_handler(std::string url_regex) {
void Webserver::deliver_file(boost::string_view target)
{
static boost::regex file{"/([\\w\\d]{1-100}\\.[\\w\\d]{1-4})"};
boost::cmatch m;
if (boost::regex_match(target.data(), m, file)) {
fs::path p{_doc_root};
p += m[1];
}
else {
}
}
Webserver::handler_t Webserver::find_handler(request& r, boost::cmatch& m)
{
std::lock_guard< std::mutex > lock(_mtx);
for (auto it=_urls.begin(); it!=_urls.end(); ++it) {
if (boost::regex_match(r.target().data(), m, it->second.regex))
return it->second.handler;


Loading…
Cancel
Save