http_session.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * Copyright (c) 2017-2023 zhllxt
  3. *
  4. * author : zhllxt
  5. * email : 37792738@qq.com
  6. *
  7. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. */
  10. #ifndef __ASIO2_HTTP_SESSION_HPP__
  11. #define __ASIO2_HTTP_SESSION_HPP__
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. #pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <asio2/base/detail/push_options.hpp>
  16. #include <asio2/tcp/tcp_session.hpp>
  17. #include <asio2/http/impl/ws_stream_cp.hpp>
  18. #include <asio2/http/impl/http_send_op.hpp>
  19. #include <asio2/http/impl/http_recv_op.hpp>
  20. #include <asio2/http/impl/ws_send_op.hpp>
  21. #include <asio2/http/detail/http_router.hpp>
  22. namespace asio2::detail
  23. {
  24. struct template_args_http_session : public template_args_tcp_session
  25. {
  26. using stream_t = websocket::stream<typename template_args_tcp_session::socket_t&>;
  27. using body_t = http::string_body;
  28. using buffer_t = beast::flat_buffer;
  29. using send_data_t = std::string_view;
  30. using recv_data_t = std::string_view;
  31. };
  32. ASIO2_CLASS_FORWARD_DECLARE_BASE;
  33. ASIO2_CLASS_FORWARD_DECLARE_TCP_BASE;
  34. ASIO2_CLASS_FORWARD_DECLARE_TCP_SERVER;
  35. ASIO2_CLASS_FORWARD_DECLARE_TCP_SESSION;
  36. template<class derived_t, class args_t = template_args_http_session>
  37. class http_session_impl_t
  38. : public tcp_session_impl_t<derived_t, args_t>
  39. , public http_send_op <derived_t, args_t>
  40. , public http_recv_op <derived_t, args_t>
  41. , public ws_stream_cp <derived_t, args_t>
  42. , public ws_send_op <derived_t, args_t>
  43. {
  44. ASIO2_CLASS_FRIEND_DECLARE_BASE;
  45. ASIO2_CLASS_FRIEND_DECLARE_TCP_BASE;
  46. ASIO2_CLASS_FRIEND_DECLARE_TCP_SERVER;
  47. ASIO2_CLASS_FRIEND_DECLARE_TCP_SESSION;
  48. public:
  49. using super = tcp_session_impl_t <derived_t, args_t>;
  50. using self = http_session_impl_t<derived_t, args_t>;
  51. using args_type = args_t;
  52. using key_type = std::size_t;
  53. using body_type = typename args_t::body_t;
  54. using buffer_type = typename args_t::buffer_t;
  55. using send_data_t = typename args_t::send_data_t;
  56. using recv_data_t = typename args_t::recv_data_t;
  57. using ws_stream_comp = ws_stream_cp<derived_t, args_t>;
  58. using super::send;
  59. using super::async_send;
  60. public:
  61. /**
  62. * @brief constructor
  63. */
  64. explicit http_session_impl_t(
  65. http_router_t<derived_t, args_t> & router,
  66. std::filesystem::path & root_directory,
  67. bool is_arg0_session,
  68. bool support_websocket,
  69. session_mgr_t<derived_t> & sessions,
  70. listener_t & listener,
  71. std::shared_ptr<io_t> rwio,
  72. std::size_t init_buf_size,
  73. std::size_t max_buf_size
  74. )
  75. : super(sessions, listener, std::move(rwio), init_buf_size, max_buf_size)
  76. , http_send_op<derived_t, args_t>()
  77. , ws_stream_cp<derived_t, args_t>()
  78. , ws_send_op <derived_t, args_t>()
  79. , req_()
  80. , rep_()
  81. , router_(router)
  82. , root_directory_ (root_directory)
  83. , is_arg0_session_ (is_arg0_session)
  84. , support_websocket_(support_websocket)
  85. {
  86. this->silence_timeout_ = std::chrono::milliseconds(http_silence_timeout);
  87. }
  88. /**
  89. * @brief destructor
  90. */
  91. ~http_session_impl_t()
  92. {
  93. }
  94. protected:
  95. /**
  96. * @brief start the session for prepare to recv/send msg
  97. */
  98. template<typename C>
  99. inline void start(std::shared_ptr<ecs_t<C>> ecs)
  100. {
  101. this->rep_.set_root_directory(this->root_directory_);
  102. this->rep_.session_ptr_ = this->derived().selfptr();
  103. this->rep_.defer_callback_ = [this, ecs, wptr = std::weak_ptr<derived_t>(this->derived().selfptr())]
  104. () mutable
  105. {
  106. std::shared_ptr<derived_t> this_ptr = wptr.lock();
  107. ASIO2_ASSERT(this_ptr);
  108. if (this_ptr)
  109. {
  110. this->derived()._do_send_http_response(std::move(this_ptr), std::move(ecs), this->rep_.base());
  111. }
  112. };
  113. super::start(std::move(ecs));
  114. }
  115. public:
  116. /**
  117. * @brief destroy the content of all member variables, this is used for solve the memory leaks.
  118. * After this function is called, this class object cannot be used again.
  119. */
  120. inline void destroy()
  121. {
  122. derived_t& derive = this->derived();
  123. derive.ws_stream_.reset();
  124. super::destroy();
  125. }
  126. public:
  127. /**
  128. * @brief get this object hash key,used for session map
  129. */
  130. inline key_type hash_key() const noexcept
  131. {
  132. return reinterpret_cast<key_type>(this);
  133. }
  134. inline bool is_websocket() const noexcept { return (bool(this->websocket_router_)); }
  135. inline bool is_http () const noexcept { return (!(this->is_websocket())); }
  136. /**
  137. * @brief get the request object, same as get_request
  138. */
  139. inline http::web_request & request() noexcept { return this->req_; }
  140. /**
  141. * @brief get the request object, same as get_request
  142. */
  143. inline const http::web_request & request() const noexcept { return this->req_; }
  144. /**
  145. * @brief get the response object, same as get_response
  146. */
  147. inline http::web_response& response() noexcept { return this->rep_; }
  148. /**
  149. * @brief get the response object, same as get_response
  150. */
  151. inline const http::web_response& response() const noexcept { return this->rep_; }
  152. /**
  153. * @brief get the request object
  154. */
  155. inline http::web_request & get_request() noexcept { return this->req_; }
  156. /**
  157. * @brief get the request object
  158. */
  159. inline const http::web_request & get_request() const noexcept { return this->req_; }
  160. /**
  161. * @brief get the response object
  162. */
  163. inline http::web_response& get_response() noexcept { return this->rep_; }
  164. /**
  165. * @brief get the response object
  166. */
  167. inline const http::web_response& get_response() const noexcept { return this->rep_; }
  168. /**
  169. * @brief set how to send the http response in the bind_recv callback
  170. * automatic - The framework automatically send the http response
  171. * manual - You need to send the http response youself
  172. */
  173. inline derived_t& set_response_mode(asio2::response_mode mode)
  174. {
  175. this->response_mode_ = mode;
  176. return (static_cast<derived_t&>(*this));
  177. }
  178. /**
  179. * @brief get the response mode
  180. */
  181. inline asio2::response_mode get_response_mode() const { return this->response_mode_; }
  182. protected:
  183. inline http_router_t<derived_t, args_t>& _router() noexcept
  184. {
  185. return (this->router_);
  186. }
  187. template<typename C>
  188. inline void _do_init(std::shared_ptr<derived_t>& this_ptr, std::shared_ptr<ecs_t<C>>& ecs)
  189. {
  190. super::_do_init(this_ptr, ecs);
  191. if (this->support_websocket_)
  192. {
  193. this->derived()._ws_init(ecs, this->derived().stream());
  194. }
  195. }
  196. template<typename DeferEvent>
  197. inline void _post_shutdown(const error_code& ec, std::shared_ptr<derived_t> this_ptr, DeferEvent chain)
  198. {
  199. ASIO2_LOG_DEBUG("http_session::_post_shutdown: {} {}", ec.value(), ec.message());
  200. if (this->derived().is_http())
  201. {
  202. super::_post_shutdown(ec, std::move(this_ptr), std::move(chain));
  203. }
  204. else
  205. {
  206. this->derived()._ws_stop(this_ptr, defer_event
  207. {
  208. [this, ec, this_ptr, e = chain.move_event()] (event_queue_guard<derived_t> g) mutable
  209. {
  210. super::_post_shutdown(ec, std::move(this_ptr), defer_event(std::move(e), std::move(g)));
  211. }, chain.move_guard()
  212. });
  213. }
  214. }
  215. template<typename DeferEvent>
  216. inline void _handle_stop(const error_code& ec, std::shared_ptr<derived_t> this_ptr, DeferEvent chain)
  217. {
  218. // can not use std::move(this_ptr), beacuse after handle stop with std::move(this_ptr),
  219. // this object maybe destroyed, then call "this" will crash.
  220. super::_handle_stop(ec, this_ptr, std::move(chain));
  221. // reset the callback shared_ptr, to avoid the callback owned this self shared_ptr.
  222. this->websocket_router_.reset();
  223. }
  224. template<typename C, class MessageT>
  225. inline void _send_http_response(
  226. std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs, MessageT& msg)
  227. {
  228. ASIO2_ASSERT(this->derived().io_->running_in_this_thread());
  229. if (this->rep_.defer_guard_)
  230. {
  231. this->rep_.defer_guard_.reset();
  232. }
  233. else
  234. {
  235. if (this->response_mode_ == asio2::response_mode::automatic)
  236. {
  237. this->derived()._do_send_http_response(std::move(this_ptr), std::move(ecs), msg);
  238. }
  239. // if the manual mode is used, then the user maybe use async send to send the
  240. // response by self, at this time, the post recv will can't be called automaticly,
  241. // so we need to call it manualy.
  242. // But there may be some drawbacks in this situation:
  243. // we can't call the post recv inside the async send callback, beacuse the
  244. // user maybe call async send with a string, and the string is just half of
  245. // http protocol data, and we don't know when the all completed http protocol
  246. // data will send finished.
  247. // so we have to call the post recv directly at here.
  248. // So the user should be best to send a completed http protocol packet at once.
  249. else
  250. {
  251. this->derived()._post_recv(std::move(this_ptr), std::move(ecs));
  252. }
  253. }
  254. }
  255. template<typename C, class MessageT>
  256. inline void _do_send_http_response_impl(
  257. std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs, MessageT& msg)
  258. {
  259. ASIO2_ASSERT(this->is_http());
  260. ASIO2_ASSERT(this->io_->running_in_this_thread());
  261. derived_t& derive = this->derived();
  262. if (derive.is_websocket())
  263. return;
  264. if (!derive.is_started())
  265. return;
  266. // be careful: here we pushed the reference of the msg into the queue, so the msg object
  267. // must can't be destroyed or modifyed.
  268. derive.push_event([&derive, this_ptr = std::move(this_ptr), ecs = std::move(ecs), &msg]
  269. (event_queue_guard<derived_t> g) mutable
  270. {
  271. // use this_ptr to instead of std::move(this_ptr) in the lambda capture has better safety.
  272. derive._do_send(msg,
  273. [&derive, this_ptr, ecs = std::move(ecs), g = std::move(g)]
  274. (const error_code&, std::size_t) mutable
  275. {
  276. ASIO2_ASSERT(!g.is_empty());
  277. #if defined(ASIO2_ENABLE_LOG)
  278. auto now = std::chrono::system_clock::now();
  279. auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
  280. ASIO2_LOG_TRACE("http_session::send {:%Y-%m-%d %H:%M:%S}.{:03d} {}",
  281. now, ms % 1000, derive.req_.target());
  282. #endif
  283. // after send the response, we check if the client should be disconnect.
  284. if (derive.req_.need_eof())
  285. {
  286. ASIO2_LOG_DEBUG("http_session send response need_eof");
  287. // session maybe don't need check the state.
  288. //if (derive.state_ == state_t::started)
  289. derive._do_disconnect(asio::error::operation_aborted, std::move(this_ptr));
  290. }
  291. else
  292. {
  293. derive._post_recv(std::move(this_ptr), std::move(ecs));
  294. }
  295. });
  296. });
  297. }
  298. template<typename C, class MessageT>
  299. inline void _do_send_http_response(
  300. std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs, MessageT& msg)
  301. {
  302. derived_t& derive = this->derived();
  303. if (derive.io_->running_in_this_thread())
  304. {
  305. derive._do_send_http_response_impl(std::move(this_ptr), std::move(ecs), msg);
  306. return;
  307. }
  308. asio::post(derive.io_->context(), make_allocator(derive.wallocator(),
  309. [&derive, this_ptr = std::move(this_ptr), ecs = std::move(ecs), &msg]() mutable
  310. {
  311. derive._do_send_http_response_impl(std::move(this_ptr), std::move(ecs), msg);
  312. }));
  313. }
  314. protected:
  315. template<class Data, class Callback>
  316. inline bool _do_send(Data& data, Callback&& callback)
  317. {
  318. if (this->derived().is_websocket())
  319. return this->derived()._ws_send(data, std::forward<Callback>(callback));
  320. return this->derived()._http_send(data, std::forward<Callback>(callback));
  321. }
  322. template<class Data>
  323. inline send_data_t _rdc_convert_to_send_data(Data& data) noexcept
  324. {
  325. ASIO2_ASSERT(this->websocket_router_ && "Only available in websocket mode");
  326. set_last_error(asio::error::operation_not_supported);
  327. auto buffer = asio::buffer(data);
  328. return send_data_t{ reinterpret_cast<
  329. std::string_view::const_pointer>(buffer.data()),buffer.size() };
  330. }
  331. template<class Invoker>
  332. inline void _rdc_invoke_with_none(const error_code& ec, Invoker& invoker)
  333. {
  334. ASIO2_ASSERT(this->websocket_router_ && "Only available in websocket mode");
  335. if (this->derived().is_websocket() && invoker)
  336. invoker(ec, send_data_t{}, recv_data_t{});
  337. }
  338. template<class Invoker>
  339. inline void _rdc_invoke_with_recv(const error_code& ec, Invoker& invoker, recv_data_t data)
  340. {
  341. ASIO2_ASSERT(this->websocket_router_ && "Only available in websocket mode");
  342. if (this->derived().is_websocket() && invoker)
  343. invoker(ec, send_data_t{}, data);
  344. }
  345. template<class Invoker>
  346. inline void _rdc_invoke_with_send(const error_code& ec, Invoker& invoker, send_data_t data)
  347. {
  348. ASIO2_ASSERT(this->websocket_router_ && "Only available in websocket mode");
  349. if (this->derived().is_websocket() && invoker)
  350. invoker(ec, data, recv_data_t{});
  351. }
  352. protected:
  353. template<typename C>
  354. inline void _post_recv(std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs)
  355. {
  356. this->derived()._http_post_recv(std::move(this_ptr), std::move(ecs));
  357. }
  358. template<typename C>
  359. inline void _handle_recv(
  360. const error_code& ec, std::size_t bytes_recvd,
  361. std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs)
  362. {
  363. this->derived()._http_handle_recv(ec, bytes_recvd, std::move(this_ptr), std::move(ecs));
  364. }
  365. template<typename C, typename DeferEvent>
  366. inline void _handle_upgrade(
  367. const error_code& ec,
  368. std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs, DeferEvent chain)
  369. {
  370. this->derived().sessions_.post(
  371. [this, ec, this_ptr = std::move(this_ptr), ecs = std::move(ecs), chain = std::move(chain)]
  372. () mutable
  373. {
  374. set_last_error(ec);
  375. this->derived()._fire_upgrade(this_ptr);
  376. if (ec)
  377. {
  378. this->derived()._do_disconnect(ec, std::move(this_ptr), std::move(chain));
  379. return;
  380. }
  381. asio::post(this->derived().io_->context(), make_allocator(this->derived().wallocator(),
  382. [this, this_ptr = std::move(this_ptr), ecs = std::move(ecs), chain = std::move(chain)]
  383. () mutable
  384. {
  385. detail::ignore_unused(chain);
  386. this->derived()._post_recv(std::move(this_ptr), std::move(ecs));
  387. }));
  388. });
  389. }
  390. template<typename C>
  391. inline bool _check_upgrade(std::shared_ptr<derived_t>& this_ptr, std::shared_ptr<ecs_t<C>>& ecs)
  392. {
  393. derived_t& derive = this->derived();
  394. if (this->support_websocket_ && derive.is_http() && this->req_.is_upgrade())
  395. {
  396. this->websocket_router_ = this->router_.template _find<false>(this->req_, this->rep_);
  397. if (this->websocket_router_)
  398. {
  399. this->req_.ws_frame_type_ = websocket::frame::open;
  400. this->req_.ws_frame_data_ = {};
  401. if (this->router_._route(this_ptr, this->req_, this->rep_))
  402. {
  403. derive.silence_timeout_ = std::chrono::milliseconds(tcp_silence_timeout);
  404. derive._ws_start(this_ptr, ecs, derive.stream());
  405. derive._post_control_callback(this_ptr, ecs);
  406. derive.push_event(
  407. [&derive, this_ptr, ecs](event_queue_guard<derived_t> g) mutable
  408. {
  409. derive._post_upgrade(
  410. this_ptr, std::move(ecs), derive.req_.base(),
  411. defer_event([](event_queue_guard<derived_t>) {}, std::move(g)));
  412. });
  413. }
  414. else
  415. {
  416. this->req_.ws_frame_type_ = websocket::frame::unknown;
  417. this->req_.ws_frame_data_ = {};
  418. this->websocket_router_.reset();
  419. derive._send_http_response(this_ptr, ecs, this->rep_.base());
  420. }
  421. // If find websocket router, the router callback must has been called,
  422. // so as long as we find the websocket router, we return true
  423. // If don't do this, the fire recv will be called, then the router callback
  424. // will be called again.
  425. return true;
  426. }
  427. }
  428. return false;
  429. }
  430. template<typename C>
  431. inline void _handle_control_ping(
  432. beast::string_view payload, std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs)
  433. {
  434. detail::ignore_unused(payload, this_ptr, ecs);
  435. this->req_.ws_frame_type_ = websocket::frame::ping;
  436. this->req_.ws_frame_data_ = payload;
  437. this->router_._route(this_ptr, this->req_, this->rep_);
  438. }
  439. template<typename C>
  440. inline void _handle_control_pong(
  441. beast::string_view payload, std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs)
  442. {
  443. detail::ignore_unused(payload, this_ptr, ecs);
  444. this->req_.ws_frame_type_ = websocket::frame::pong;
  445. this->req_.ws_frame_data_ = payload;
  446. this->router_._route(this_ptr, this->req_, this->rep_);
  447. }
  448. template<typename C>
  449. inline void _handle_control_close(
  450. beast::string_view payload, std::shared_ptr<derived_t> this_ptr, std::shared_ptr<ecs_t<C>> ecs)
  451. {
  452. detail::ignore_unused(payload, this_ptr, ecs);
  453. this->req_.ws_frame_type_ = websocket::frame::close;
  454. this->req_.ws_frame_data_ = payload;
  455. this->router_._route(this_ptr, this->req_, this->rep_);
  456. // session maybe don't need check the state.
  457. //if (this->derived().state_ == state_t::started)
  458. {
  459. ASIO2_LOG_DEBUG("http_session::_handle_control_close _do_disconnect");
  460. this->derived()._do_disconnect(websocket::error::closed, std::move(this_ptr));
  461. }
  462. }
  463. inline void _fire_upgrade(std::shared_ptr<derived_t>& this_ptr)
  464. {
  465. // the _fire_upgrade must be executed in the thread 0.
  466. ASIO2_ASSERT(this->sessions_.io_->running_in_this_thread());
  467. this->listener_.notify(event_type::upgrade, this_ptr);
  468. }
  469. template<typename C>
  470. inline void _fire_recv(std::shared_ptr<derived_t>& this_ptr, std::shared_ptr<ecs_t<C>>& ecs)
  471. {
  472. if (this->is_arg0_session_)
  473. this->listener_.notify(event_type::recv, this_ptr, this->req_, this->rep_);
  474. else
  475. this->listener_.notify(event_type::recv, this->req_, this->rep_);
  476. #if defined(ASIO2_ENABLE_LOG)
  477. auto now = std::chrono::system_clock::now();
  478. auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
  479. ASIO2_LOG_TRACE("http_session::recv {:%Y-%m-%d %H:%M:%S}.{:03d} {}",
  480. now, ms % 1000, this->req_.target());
  481. #endif
  482. auto* prep = this->router_._route(this_ptr, this->req_, this->rep_);
  483. if (this->derived().is_websocket())
  484. {
  485. this->derived()._rdc_handle_recv(this_ptr, ecs, this->req_.ws_frame_data_);
  486. }
  487. else
  488. {
  489. this->derived()._send_http_response(this_ptr, ecs, *prep);
  490. }
  491. }
  492. protected:
  493. http::web_request req_;
  494. http::web_response rep_;
  495. http_router_t<derived_t, args_t> & router_;
  496. std::filesystem::path & root_directory_;
  497. bool is_arg0_session_ = false;
  498. bool support_websocket_ = false;
  499. asio2::response_mode response_mode_ = asio2::response_mode::automatic;
  500. std::shared_ptr<typename http_router_t<derived_t, args_t>::opfun> websocket_router_;
  501. };
  502. }
  503. namespace asio2
  504. {
  505. using http_session_args = detail::template_args_http_session;
  506. template<class derived_t, class args_t>
  507. using http_session_impl_t = detail::http_session_impl_t<derived_t, args_t>;
  508. template<class derived_t>
  509. class http_session_t : public detail::http_session_impl_t<derived_t, detail::template_args_http_session>
  510. {
  511. public:
  512. using detail::http_session_impl_t<derived_t, detail::template_args_http_session>::http_session_impl_t;
  513. };
  514. class http_session : public http_session_t<http_session>
  515. {
  516. public:
  517. using http_session_t<http_session>::http_session_t;
  518. };
  519. }
  520. #if defined(ASIO2_INCLUDE_RATE_LIMIT)
  521. #include <asio2/tcp/tcp_stream.hpp>
  522. namespace asio2
  523. {
  524. struct http_rate_session_args : public http_session_args
  525. {
  526. using socket_t = asio2::tcp_stream<asio2::simple_rate_policy>;
  527. using stream_t = websocket::stream<socket_t&>;
  528. };
  529. template<class derived_t>
  530. class http_rate_session_t : public asio2::http_session_impl_t<derived_t, http_rate_session_args>
  531. {
  532. public:
  533. using asio2::http_session_impl_t<derived_t, http_rate_session_args>::http_session_impl_t;
  534. };
  535. class http_rate_session : public asio2::http_rate_session_t<http_rate_session>
  536. {
  537. public:
  538. using asio2::http_rate_session_t<http_rate_session>::http_rate_session_t;
  539. };
  540. }
  541. #endif
  542. #include <asio2/base/detail/pop_options.hpp>
  543. #endif // !__ASIO2_HTTP_SESSION_HPP__