17 #if defined(__clang__)
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wconversion"
21 #include <boost/asio.hpp>
22 #include <boost/asio/ssl.hpp>
23 #if defined(__clang__)
24 #pragma clang diagnostic pop
26 #include <boost/bind.hpp>
28 #include "pplx/threadpool.h"
29 #include "cpprest/details/http_server.h"
61 typedef void (
connection::*ResponseFuncPtr) (
const http_response &response,
const boost::system::error_code& ec);
63 std::unique_ptr<boost::asio::ip::tcp::socket> m_socket;
64 boost::asio::streambuf m_request_buf;
65 boost::asio::streambuf m_response_buf;
69 size_t m_read, m_write;
70 size_t m_read_size, m_write_size;
73 std::atomic<int> m_refs;
75 std::unique_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>> m_ssl_stream;
79 : m_socket(std::move(socket))
88 boost::asio::ssl::context ssl_context(boost::asio::ssl::context::sslv23);
89 ssl_context_callback(ssl_context);
90 m_ssl_stream = utility::details::make_unique<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>>(*m_socket, ssl_context);
91 m_ssl_stream->async_handshake(boost::asio::ssl::stream_base::server, [
this](
const boost::system::error_code&) { this->start_request_response(); });
95 start_request_response();
105 void start_request_response();
106 void handle_http_line(
const boost::system::error_code& ec);
107 void handle_headers();
108 void handle_body(
const boost::system::error_code& ec);
109 void handle_chunked_header(
const boost::system::error_code& ec);
110 void handle_chunked_body(
const boost::system::error_code& ec,
int toWrite);
111 void dispatch_request_to_listener();
112 void do_response(
bool bad_request);
113 void async_write(ResponseFuncPtr response_func_ptr,
const http_response &response);
114 template <
typename CompletionCondition,
typename Handler>
115 void async_read(CompletionCondition &&condition, Handler &&read_handler);
116 void async_read_until();
117 template <
typename ReadHandler>
118 void async_read_until_buffersize(
size_t size,
const ReadHandler &handler);
120 void cancel_sending_response_with_error(
const http_response &response,
const std::exception_ptr &);
121 void handle_headers_written(
const http_response &response,
const boost::system::error_code& ec);
122 void handle_write_large_response(
const http_response &response,
const boost::system::error_code& ec);
123 void handle_write_chunked_response(
const http_response &response,
const boost::system::error_code& ec);
124 void handle_response_written(
const http_response &response,
const boost::system::error_code& ec);
125 void finish_request_response();
133 std::unique_ptr<boost::asio::ip::tcp::acceptor> m_acceptor;
134 std::map<std::string, web::http::experimental::listener::details::http_listener_impl* > m_listeners;
139 std::set<connection*> m_connections;
147 const std::function<void(boost::asio::ssl::context&)>& m_ssl_context_callback;
154 , m_connections_lock()
157 , m_is_https(is_https)
160 m_all_connections_complete.set();
162 std::istringstream hostport_in(hostport);
163 hostport_in.imbue(std::locale::classic());
165 std::getline(hostport_in, m_host,
':');
166 std::getline(hostport_in, m_port);
181 void on_accept(boost::asio::ip::tcp::socket* socket,
const boost::system::error_code& ec);
189 bool operator()(
const std::string& left,
const std::string& right)
const
191 return boost::ilexicographical_compare(left, right);
201 std::map<std::string, std::unique_ptr<details::hostport_listener>,
iequal_to> m_listeners;
202 std::unordered_map<details::http_listener_impl *, std::unique_ptr<pplx::extensibility::reader_writer_lock_t>> m_registered_listeners;
Definition: http_server_asio.h:128
Configuration class used to set various options when constructing and http_listener instance...
Definition: http_listener.h:54
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: pplxtasks.h:2934
Represents an HTTP response.
Definition: http_msg.h:383
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37
Definition: http_server_asio.h:45
virtual pplx::task< void > stop()
Stop processing and listening for incoming requests.
Definition: http_server_asio.h:58
Definition: http_server_asio.h:187
Recursive mutex
Definition: pplxlinux.h:196
Definition: http_server_asio.h:195
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: pplxtasks.h:4173
const std::function< void(boost::asio::ssl::context &)> & get_ssl_context_callback() const
Get the callback of ssl context
Definition: http_listener.h:142
Manual reset event
Definition: pplxlinux.h:84
Represents an HTTP request.
Definition: http_msg.h:771
Reader writer lock
Definition: pplxlinux.h:140
Internal class for pointer to implementation design pattern.
Definition: http_listener.h:171
Base structure for associating internal server information with an HTTP request/response.
Definition: http_msg.h:338
Interface http listeners interact with for receiving and responding to http requests.
Definition: http_server.h:42
virtual pplx::task< void > start()
Start listening for incoming requests.
pplx::task< void > respond(http::http_response response)
Asynchronously sends the specified http response.