diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2024-02-07 21:33:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-07 21:33:28 +0100 |
commit | 6319bafafa98e2a7a79b5bb301979c7533bb4fe5 (patch) | |
tree | 36fe56dfcf261cc677ffab8015e85c79317034c4 /src/web_service/web_backend.cpp | |
parent | Merge pull request #12909 from t895/play-store-automation (diff) | |
parent | web_backend: Fix compilation (diff) | |
download | yuzu-6319bafafa98e2a7a79b5bb301979c7533bb4fe5.tar yuzu-6319bafafa98e2a7a79b5bb301979c7533bb4fe5.tar.gz yuzu-6319bafafa98e2a7a79b5bb301979c7533bb4fe5.tar.bz2 yuzu-6319bafafa98e2a7a79b5bb301979c7533bb4fe5.tar.lz yuzu-6319bafafa98e2a7a79b5bb301979c7533bb4fe5.tar.xz yuzu-6319bafafa98e2a7a79b5bb301979c7533bb4fe5.tar.zst yuzu-6319bafafa98e2a7a79b5bb301979c7533bb4fe5.zip |
Diffstat (limited to 'src/web_service/web_backend.cpp')
-rw-r--r-- | src/web_service/web_backend.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index dff380cca..fdf3ac846 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -32,9 +32,14 @@ struct Client::Impl { Impl(std::string host_, std::string username_, std::string token_) : host{std::move(host_)}, username{std::move(username_)}, token{std::move(token_)} { std::scoped_lock lock{jwt_cache.mutex}; - if (username == jwt_cache.username && token == jwt_cache.token) { + if (this->username == jwt_cache.username && this->token == jwt_cache.token) { jwt = jwt_cache.jwt; } + + // Normalize host expression + if (!this->host.empty() && this->host.back() == '/') { + static_cast<void>(this->host.pop_back()); + } } /// A generic function handles POST, GET and DELETE request together @@ -71,18 +76,16 @@ struct Client::Impl { const std::string& jwt_ = "", const std::string& username_ = "", const std::string& token_ = "") { if (cli == nullptr) { - cli = std::make_unique<httplib::Client>(host); + cli = std::make_unique<httplib::Client>(host.c_str()); + cli->set_connection_timeout(TIMEOUT_SECONDS); + cli->set_read_timeout(TIMEOUT_SECONDS); + cli->set_write_timeout(TIMEOUT_SECONDS); } - if (!cli->is_valid()) { - LOG_ERROR(WebService, "Client is invalid, skipping request!"); - return {}; + LOG_ERROR(WebService, "Invalid URL {}", host + path); + return WebResult{WebResult::Code::InvalidURL, "Invalid URL", ""}; } - cli->set_connection_timeout(TIMEOUT_SECONDS); - cli->set_read_timeout(TIMEOUT_SECONDS); - cli->set_write_timeout(TIMEOUT_SECONDS); - httplib::Headers params; if (!jwt_.empty()) { params = { @@ -107,15 +110,15 @@ struct Client::Impl { request.headers = params; request.body = data; - httplib::Response response; - httplib::Error error; + httplib::Result result = cli->send(request); - if (!cli->send(request, response, error)) { - LOG_ERROR(WebService, "{} to {} returned null (httplib Error: {})", method, host + path, - httplib::to_string(error)); + if (!result) { + LOG_ERROR(WebService, "{} to {} returned null", method, host + path); return WebResult{WebResult::Code::LibError, "Null response", ""}; } + httplib::Response response = result.value(); + if (response.status >= 400) { LOG_ERROR(WebService, "{} to {} returned error status code: {}", method, host + path, response.status); |