| 63 | } |
| 64 | |
| 65 | HTTPWorker::HTTPWorker( |
| 66 | caf::actor_config &cfg, |
| 67 | time_t connection_timeout, |
| 68 | time_t read_timeout, |
| 69 | time_t write_timeout, |
| 70 | bool ssl_verify) |
| 71 | : caf::event_based_actor(cfg) { |
| 72 | behavior_.assign( |
| 73 | [=](xstudio::broadcast::broadcast_down_atom, const caf::actor_addr &) {}, |
| 74 | [=](http_delete_atom, |
| 75 | const std::string &scheme_host_port, |
| 76 | const std::string &path, |
| 77 | const httplib::Headers &headers, |
| 78 | const std::string &body, |
| 79 | const std::string &content_type) -> result<httplib::Response> { |
| 80 | |
| 81 | #ifdef LOG_CALLS |
| 82 | spdlog::stopwatch sw; |
| 83 | spdlog::info("http_delete_atom {}", path); |
| 84 | #endif |
| 85 | |
| 86 | try { |
| 87 | httplib::Client cli(scheme_host_port.c_str()); |
| 88 | cli.set_follow_location(true); |
| 89 | cli.set_connection_timeout(connection_timeout, 0); |
| 90 | cli.set_read_timeout(read_timeout, 0); |
| 91 | cli.set_write_timeout(write_timeout, 0); |
| 92 | cli.enable_server_certificate_verification(ssl_verify); |
| 93 | auto res = [&]() -> httplib::Result { |
| 94 | if (content_type.empty()) |
| 95 | return cli.Delete(path.c_str(), headers); |
| 96 | return cli.Delete(path.c_str(), headers, body, content_type.c_str()); |
| 97 | }(); |
| 98 | |
| 99 | if (res.error() != httplib::Error::Success) |
| 100 | return make_error(hce::rest_error, get_error_string(res.error())); |
| 101 | |
| 102 | #ifdef LOG_CALLS |
| 103 | spdlog::info("http_delete_atom {} {:.3f}", path, sw); |
| 104 | #endif |
| 105 | |
| 106 | if (res) |
| 107 | return *res; |
| 108 | return make_error(hce::connection_error, "Empty response"); |
| 109 | } catch (const std::exception &err) { |
| 110 | return make_error(hce::connection_error, err.what()); |
| 111 | } |
| 112 | }, |
| 113 | |
| 114 | [=](http_delete_simple_atom, |
| 115 | const std::string &scheme_host_port, |
| 116 | const std::string &path, |
| 117 | const httplib::Headers &headers, |
| 118 | const std::string &body, |
| 119 | const std::string &content_type) -> result<std::string> { |
| 120 | auto rp = make_response_promise<std::string>(); |
| 121 | mail(http_delete_atom_v, scheme_host_port, path, headers, body, content_type) |
| 122 | .request(actor_cast<caf::actor>(this), infinite) |
nothing calls this directly
no test coverage detected