23 #ifndef TGBOT_HTTPSERVER_H 24 #define TGBOT_HTTPSERVER_H 28 #include <boost/asio.hpp> 38 template<
typename Protocol>
45 typedef std::function<std::string (const std::string&, const std::map<std::string, std::string>)>
ServerHandler;
54 std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(
new boost::asio::basic_stream_socket<Protocol>(
_acceptor->get_io_service()));
55 std::shared_ptr<Connection> connection(
new Connection(socket,
_handler));
56 _acceptor->async_accept(*connection->socket, [
this, connection]() {
75 boost::asio::socket_base::keep_alive option(
true);
82 std::map<std::string, std::string> headers;
88 std::shared_ptr<boost::asio::basic_stream_socket<Protocol>>
socket;
96 std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>
_acceptor;
102 #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
std::string parseResponse(const std::string &data, std::map< std::string, std::string > &headers)
Connection(std::shared_ptr< boost::asio::basic_stream_socket< Protocol >> &socket, const ServerHandler &handler)
const ServerHandler _handler
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::map< std::string, std::string >)> ServerHandler
boost::asio::io_service _ioService