diff options
Diffstat (limited to 'src/web_service/web_backend.cpp')
-rw-r--r-- | src/web_service/web_backend.cpp | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 74e287045..67183e64c 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -7,7 +7,6 @@ #include <mutex> #include <string> -#include <LUrlParser.h> #include <fmt/format.h> #include <httplib.h> @@ -19,9 +18,6 @@ namespace WebService { constexpr std::array<const char, 1> API_VERSION{'1'}; -constexpr int HTTP_PORT = 80; -constexpr int HTTPS_PORT = 443; - constexpr std::size_t TIMEOUT_SECONDS = 30; struct Client::Impl { @@ -67,28 +63,17 @@ struct Client::Impl { const std::string& jwt = "", const std::string& username = "", const std::string& token = "") { if (cli == nullptr) { - auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); - int port; - if (parsedUrl.m_Scheme == "http") { - if (!parsedUrl.GetPort(&port)) { - port = HTTP_PORT; - } - cli = std::make_unique<httplib::Client>(parsedUrl.m_Host.c_str(), port); - } else if (parsedUrl.m_Scheme == "https") { - if (!parsedUrl.GetPort(&port)) { - port = HTTPS_PORT; - } - cli = std::make_unique<httplib::SSLClient>(parsedUrl.m_Host.c_str(), port); - } else { - LOG_ERROR(WebService, "Bad URL scheme {}", parsedUrl.m_Scheme); - return WebResult{WebResult::Code::InvalidURL, "Bad URL scheme", ""}; - } + cli = std::make_unique<httplib::Client>(host.c_str()); } - if (cli == nullptr) { - LOG_ERROR(WebService, "Invalid URL {}", host + path); - return WebResult{WebResult::Code::InvalidURL, "Invalid URL", ""}; + + if (!cli->is_valid()) { + LOG_ERROR(WebService, "Client is invalid, skipping request!"); + return {}; } - cli->set_timeout_sec(TIMEOUT_SECONDS); + + cli->set_connection_timeout(TIMEOUT_SECONDS); + cli->set_read_timeout(TIMEOUT_SECONDS); + cli->set_write_timeout(TIMEOUT_SECONDS); httplib::Headers params; if (!jwt.empty()) { |