| 66 | } |
| 67 | |
| 68 | static std::pair<httplib::Client, common_http_url> common_http_client(const std::string & url) { |
| 69 | common_http_url parts = common_http_parse_url(url); |
| 70 | |
| 71 | if (parts.host.empty()) { |
| 72 | throw std::runtime_error("error: invalid URL format"); |
| 73 | } |
| 74 | |
| 75 | #ifndef CPPHTTPLIB_OPENSSL_SUPPORT |
| 76 | if (parts.scheme == "https") { |
| 77 | throw std::runtime_error( |
| 78 | "HTTPS is not supported. Please rebuild with one of:\n" |
| 79 | " -DLLAMA_BUILD_BORINGSSL=ON\n" |
| 80 | " -DLLAMA_BUILD_LIBRESSL=ON\n" |
| 81 | " -DLLAMA_OPENSSL=ON (default, requires OpenSSL dev files installed)" |
| 82 | ); |
| 83 | } |
| 84 | #endif |
| 85 | |
| 86 | httplib::Client cli(parts.scheme + "://" + parts.host + ":" + std::to_string(parts.port)); |
| 87 | |
| 88 | if (!parts.user.empty()) { |
| 89 | cli.set_basic_auth(parts.user, parts.password); |
| 90 | } |
| 91 | |
| 92 | cli.set_follow_location(true); |
| 93 | |
| 94 | return { std::move(cli), std::move(parts) }; |
| 95 | } |
| 96 | |
| 97 | static std::string common_http_show_masked_url(const common_http_url & parts) { |
| 98 | return parts.scheme + "://" + (parts.user.empty() ? "" : "****:****@") + parts.host + parts.path; |
no test coverage detected