| 108 | } |
| 109 | |
| 110 | GenerateResult HttpRequestHandler::make_request(const std::string& path, |
| 111 | const httplib::Headers& headers, |
| 112 | const std::string& body, |
| 113 | const std::string& content_type, |
| 114 | ResponseHandler handler) { |
| 115 | try { |
| 116 | // Combine base_path with the endpoint path |
| 117 | std::string full_path = config_.base_path + path; |
| 118 | |
| 119 | ai::logger::log_debug("Making {} request to {}:{}{}", |
| 120 | config_.use_ssl ? "HTTPS" : "HTTP", config_.host, |
| 121 | full_path, |
| 122 | " with body size: " + std::to_string(body.size())); |
| 123 | |
| 124 | if (config_.use_ssl) { |
| 125 | httplib::SSLClient cli(config_.host); |
| 126 | cli.set_connection_timeout(config_.connection_timeout_sec, 0); |
| 127 | cli.set_read_timeout(config_.read_timeout_sec, 0); |
| 128 | cli.enable_server_certificate_verification(config_.verify_ssl_cert); |
| 129 | |
| 130 | auto res = cli.Post(full_path, headers, body, content_type); |
| 131 | return handler(res, "HTTPS"); |
| 132 | } else { |
| 133 | httplib::Client cli(config_.host); |
| 134 | cli.set_connection_timeout(config_.connection_timeout_sec, 0); |
| 135 | cli.set_read_timeout(config_.read_timeout_sec, 0); |
| 136 | |
| 137 | auto res = cli.Post(full_path, headers, body, content_type); |
| 138 | return handler(res, "HTTP"); |
| 139 | } |
| 140 | } catch (const std::exception& e) { |
| 141 | ai::logger::log_error("Exception in make_request: {}", e.what()); |
| 142 | return GenerateResult(std::string("Request failed: ") + e.what()); |
| 143 | } catch (...) { |
| 144 | ai::logger::log_error("Unknown exception in make_request"); |
| 145 | return GenerateResult("Request failed: Unknown error"); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | } // namespace http |
| 150 | } // namespace ai |
nothing calls this directly
no test coverage detected