diff options
| author | 2021-01-10 22:09:56 -0700 | |
|---|---|---|
| committer | 2021-01-10 22:09:56 -0700 | |
| commit | 7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch) | |
| tree | 5056f9406dec188439cb0deb87603498243a9412 /src/web_service/web_backend.cpp | |
| parent | More forgetting... duh (diff) | |
| parent | Merge pull request #5229 from Morph1984/fullscreen-opt (diff) | |
| download | yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.gz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.xz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.zip | |
Merge remote-tracking branch 'upstream/master' into int-flags
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 @@ | |||
| 7 | #include <mutex> | 7 | #include <mutex> |
| 8 | #include <string> | 8 | #include <string> |
| 9 | 9 | ||
| 10 | #include <LUrlParser.h> | ||
| 11 | #include <fmt/format.h> | 10 | #include <fmt/format.h> |
| 12 | #include <httplib.h> | 11 | #include <httplib.h> |
| 13 | 12 | ||
| @@ -19,9 +18,6 @@ namespace WebService { | |||
| 19 | 18 | ||
| 20 | constexpr std::array<const char, 1> API_VERSION{'1'}; | 19 | constexpr std::array<const char, 1> API_VERSION{'1'}; |
| 21 | 20 | ||
| 22 | constexpr int HTTP_PORT = 80; | ||
| 23 | constexpr int HTTPS_PORT = 443; | ||
| 24 | |||
| 25 | constexpr std::size_t TIMEOUT_SECONDS = 30; | 21 | constexpr std::size_t TIMEOUT_SECONDS = 30; |
| 26 | 22 | ||
| 27 | struct Client::Impl { | 23 | struct Client::Impl { |
| @@ -67,28 +63,17 @@ struct Client::Impl { | |||
| 67 | const std::string& jwt = "", const std::string& username = "", | 63 | const std::string& jwt = "", const std::string& username = "", |
| 68 | const std::string& token = "") { | 64 | const std::string& token = "") { |
| 69 | if (cli == nullptr) { | 65 | if (cli == nullptr) { |
| 70 | auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); | 66 | cli = std::make_unique<httplib::Client>(host.c_str()); |
| 71 | int port; | ||
| 72 | if (parsedUrl.m_Scheme == "http") { | ||
| 73 | if (!parsedUrl.GetPort(&port)) { | ||
| 74 | port = HTTP_PORT; | ||
| 75 | } | ||
| 76 | cli = std::make_unique<httplib::Client>(parsedUrl.m_Host.c_str(), port); | ||
| 77 | } else if (parsedUrl.m_Scheme == "https") { | ||
| 78 | if (!parsedUrl.GetPort(&port)) { | ||
| 79 | port = HTTPS_PORT; | ||
| 80 | } | ||
| 81 | cli = std::make_unique<httplib::SSLClient>(parsedUrl.m_Host.c_str(), port); | ||
| 82 | } else { | ||
| 83 | LOG_ERROR(WebService, "Bad URL scheme {}", parsedUrl.m_Scheme); | ||
| 84 | return WebResult{WebResult::Code::InvalidURL, "Bad URL scheme", ""}; | ||
| 85 | } | ||
| 86 | } | 67 | } |
| 87 | if (cli == nullptr) { | 68 | |
| 88 | LOG_ERROR(WebService, "Invalid URL {}", host + path); | 69 | if (!cli->is_valid()) { |
| 89 | return WebResult{WebResult::Code::InvalidURL, "Invalid URL", ""}; | 70 | LOG_ERROR(WebService, "Client is invalid, skipping request!"); |
| 71 | return {}; | ||
| 90 | } | 72 | } |
| 91 | cli->set_timeout_sec(TIMEOUT_SECONDS); | 73 | |
| 74 | cli->set_connection_timeout(TIMEOUT_SECONDS); | ||
| 75 | cli->set_read_timeout(TIMEOUT_SECONDS); | ||
| 76 | cli->set_write_timeout(TIMEOUT_SECONDS); | ||
| 92 | 77 | ||
| 93 | httplib::Headers params; | 78 | httplib::Headers params; |
| 94 | if (!jwt.empty()) { | 79 | if (!jwt.empty()) { |