You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <boost/asio/ip/tcp.hpp>
|
|
#include <boost/regex.hpp>
|
|
|
|
namespace net = boost::asio;
|
|
using tcp = boost::asio::ip::tcp;
|
|
|
|
namespace pEp {
|
|
// class Webserver
|
|
//
|
|
// when an URL handler is present it is called for each matching URL
|
|
// otherwise this server is searching for static files in doc_root
|
|
// only registered file types and no subdirectories are served for
|
|
// static files
|
|
|
|
class Webserver {
|
|
public:
|
|
typedef boost::regex url_t;
|
|
typedef std::function< void(boost::cmatch) > handler_t;
|
|
|
|
private:
|
|
net::io_context _ioc;
|
|
tcp::acceptor _acceptor;
|
|
std::string _doc_root;
|
|
std::vector< std::pair< url_t, handler_t > > _urls;
|
|
bool _running;
|
|
|
|
public:
|
|
Webserver(net::ip::address addr, unsigned short port, std::string doc_root);
|
|
Webserver(const Webserver&) = delete;
|
|
Webserver& operator=(const Webserver&) = delete;
|
|
~Webserver() { }
|
|
|
|
void add_url_handler(url_t url, handler_t handler);
|
|
void run();
|
|
void shutdown();
|
|
|
|
protected:
|
|
void do_session(tcp::socket& socket);
|
|
};
|
|
};
|
|
|