2#include <ossia/network/context.hpp> 
    3#include <ossia/network/http/http_client.hpp> 
    5#include <boost/algorithm/string.hpp> 
    6#include <boost/algorithm/string/erase.hpp> 
    8namespace ossia::oscquery_asio
 
   11template <
typename State>
 
   12struct http_async_answer
 
   14  static constexpr auto reserve_expect = 65535 * 8;
 
   15  std::weak_ptr<State> state;
 
   17  template <
typename T, 
typename S>
 
   18  void operator()(T& req, 
const S& str)
 
   20    if(
auto ptr = state.lock())
 
   24        ptr->self.on_text_ws_message({}, str);
 
   30template <
typename State>
 
   31struct http_async_value_answer
 
   33  static constexpr auto reserve_expect = 1500;
 
   34  std::weak_ptr<State> state;
 
   35  std::string source_address;
 
   37  template <
typename T, 
typename S>
 
   38  void operator()(T& req, 
const S& str)
 
   40    if(
auto ptr = state.lock())
 
   44        ptr->self.on_value_http_message(source_address, str);
 
   50struct http_async_error
 
   53  void operator()(T& req)
 
   61    const std::future<T>& fut, std::chrono::milliseconds timeout,
 
   62    boost::asio::io_context& ctx)
 
   64  std::future_status status = fut.wait_for(std::chrono::seconds(0));
 
   66  auto t0 = std::chrono::steady_clock::now();
 
   68  while(status != std::future_status::ready)
 
   71    if((status = fut.wait_for(std::chrono::seconds(0))) == std::future_status::ready)
 
   74    auto t1 = std::chrono::steady_clock::now();
 
   75    if(std::chrono::duration_cast<std::chrono::seconds>(t1 - t0) > timeout)
 
   84template <
typename State>
 
   85struct http_async_request
 
   86    : ossia::net::http_get_request<http_async_answer<State>, http_async_error>
 
   88  using ossia::net::http_get_request<
 
   89      http_async_answer<State>, http_async_error>::http_get_request;
 
   92template <
typename State>
 
   93struct http_async_value_request
 
   94    : ossia::net::http_get_request<http_async_value_answer<State>, http_async_error>
 
   96  using ossia::net::http_get_request<
 
   97      http_async_value_answer<State>, http_async_error>::http_get_request;
 
  100struct http_async_client_context
 
  102  using ctx = boost::asio::io_context;
 
  103  using executor = ctx::executor_type;
 
  104  using work = boost::asio::executor_work_guard<executor>;
 
  105  std::shared_ptr<work> worker;
 
  108inline std::string asio_to_ip(std::string uri)
 
  110  uri = boost::algorithm::ierase_first_copy(uri, 
"http://");
 
  111  uri = boost::algorithm::ierase_first_copy(uri, 
"https://");
 
  112  uri = boost::algorithm::ierase_first_copy(uri, 
"ws://");
 
  113  uri = boost::algorithm::ierase_first_copy(uri, 
"wss://");
 
  115  auto pos = uri.find_last_of(
':');
 
  116  if(pos != std::string::npos)
 
  117    uri.erase(pos, uri.size());