23 #ifndef TGBOT_HTTPSERVER_H 24 #define TGBOT_HTTPSERVER_H 28 #include <boost/asio.hpp> 39 template<
typename Protocol>
46 typedef std::function<std::string (const std::string&, const std::unordered_map<std::string, std::string>)>
ServerHandler;
55 auto socket(std::make_shared<boost::asio::basic_stream_socket<Protocol>>(
_acceptor->get_io_service()));
56 auto connection(std::make_shared<Connection>(socket,
_handler));
57 _acceptor->async_accept(*connection->socket, [
this, connection]() {
76 boost::asio::socket_base::keep_alive option(
true);
83 std::unordered_map<std::string, std::string> headers;
89 std::shared_ptr<boost::asio::basic_stream_socket<Protocol>>
socket;
97 std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>
_acceptor;
103 #endif //TGBOT_HTTPSERVER_H std::shared_ptr< boost::asio::basic_socket_acceptor< Protocol > > _acceptor
const ServerHandler _handler
std::shared_ptr< boost::asio::basic_stream_socket< Protocol > > socket
This class handles HTTP requests from the Internet.
void start()
Starts receiving new connections.
Connection(std::shared_ptr< boost::asio::basic_stream_socket< Protocol >> &socket, const ServerHandler &handler)
const ServerHandler _handler
void stop()
Stops receiving new connections.
HttpServer(std::shared_ptr< boost::asio::basic_socket_acceptor< Protocol >> acceptor, const ServerHandler &handler)
static HttpParser & getInstance()
std::function< std::string(const std::string &, const std::unordered_map< std::string, std::string >)> ServerHandler
boost::asio::io_service _ioService
std::string parseResponse(const std::string &data, std::unordered_map< std::string, std::string > &headers)