diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2017-06-13 19:17:11 +0200 |
|---|---|---|
| committer | Léo Lam <leo@innovatetechnologi.es> | 2017-06-13 19:17:11 +0200 |
| commit | 0d58a0bfe2f75c4ea354d0ea4bfa64514dca47ff (patch) | |
| tree | 5f51dbae4c7c1ead80a08ce9b7a71fe1ea18ae96 /Source/Core/Common/HttpRequest.cpp | |
| parent | ba3f16edbfe8b152f12a66b8fb3da215c8e52a1c (diff) | |
HttpRequest: Add support for custom timeouts
Diffstat (limited to 'Source/Core/Common/HttpRequest.cpp')
| -rw-r--r-- | Source/Core/Common/HttpRequest.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Source/Core/Common/HttpRequest.cpp b/Source/Core/Common/HttpRequest.cpp index 5c83521972..b87ce4fb98 100644 --- a/Source/Core/Common/HttpRequest.cpp +++ b/Source/Core/Common/HttpRequest.cpp @@ -22,7 +22,7 @@ public: POST, }; - Impl(); + Impl(int timeout_ms); bool IsValid() const; Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload, @@ -32,7 +32,7 @@ private: std::unique_ptr<CURL, decltype(&curl_easy_cleanup)> m_curl{curl_easy_init(), curl_easy_cleanup}; }; -HttpRequest::HttpRequest() : m_impl(std::make_unique<Impl>()) +HttpRequest::HttpRequest(int timeout_ms) : m_impl(std::make_unique<Impl>(timeout_ms)) { } @@ -61,7 +61,7 @@ HttpRequest::Response HttpRequest::Post(const std::string& url, const std::strin reinterpret_cast<const u8*>(payload.data()), payload.size()); } -HttpRequest::Impl::Impl() +HttpRequest::Impl::Impl(int timeout_ms) { if (!m_curl) return; @@ -69,7 +69,7 @@ HttpRequest::Impl::Impl() // libcurl may not have been built with async DNS support, so we disable // signal handlers to avoid a possible and likely crash if a resolve times out. curl_easy_setopt(m_curl.get(), CURLOPT_NOSIGNAL, true); - curl_easy_setopt(m_curl.get(), CURLOPT_TIMEOUT, 3); + curl_easy_setopt(m_curl.get(), CURLOPT_TIMEOUT_MS, timeout_ms); #ifdef _WIN32 // ALPN support is enabled by default but requires Windows >= 8.1. curl_easy_setopt(m_curl.get(), CURLOPT_SSL_ENABLE_ALPN, false); |
