diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-08-09 15:18:28 +0300 |
---|---|---|
committer | Roman Kuznetsov <r.kuznetsow@gmail.com> | 2017-08-09 17:13:36 +0300 |
commit | 2f29263b046dd4bc5ecc97f31ad69d9dc4739b16 (patch) | |
tree | 69126a578b42cef5b510842970f92997081cd335 /platform | |
parent | 14bb6b234d2e860924490f4b354722f1b5518653 (diff) |
[platform] http client timeout
Diffstat (limited to 'platform')
-rw-r--r-- | platform/http_client.cpp | 5 | ||||
-rw-r--r-- | platform/http_client.hpp | 3 | ||||
-rw-r--r-- | platform/http_client_apple.mm | 6 | ||||
-rw-r--r-- | platform/http_client_curl.cpp | 2 |
4 files changed, 11 insertions, 5 deletions
diff --git a/platform/http_client.cpp b/platform/http_client.cpp index aa29bee506..7688a7438c 100644 --- a/platform/http_client.cpp +++ b/platform/http_client.cpp @@ -71,6 +71,11 @@ HttpClient & HttpClient::SetRawHeader(string const & key, string const & value) return *this; } +void HttpClient::SetTimeout(double timeoutSec) +{ + m_timeoutSec = timeoutSec; +} + string const & HttpClient::UrlRequested() const { return m_urlRequested; diff --git a/platform/http_client.hpp b/platform/http_client.hpp index c4bb22d4cd..d21ef6a880 100644 --- a/platform/http_client.hpp +++ b/platform/http_client.hpp @@ -77,6 +77,7 @@ public: // TODO: "false" is now supported on Android only. HttpClient & SetHandleRedirects(bool handle_redirects); HttpClient & SetRawHeader(string const & key, string const & value); + void SetTimeout(double timeoutSec); string const & UrlRequested() const; // @returns empty string in the case of error @@ -117,6 +118,8 @@ private: unordered_map<string, string> m_headers; bool m_handleRedirects = true; bool m_loadHeaders = false; + // Use 30 seconds timeout by default. + double m_timeoutSec = 30.0; DISALLOW_COPY_AND_MOVE(HttpClient); }; diff --git a/platform/http_client_apple.mm b/platform/http_client_apple.mm index 7c366dafa0..f34e76c193 100644 --- a/platform/http_client_apple.mm +++ b/platform/http_client_apple.mm @@ -48,15 +48,11 @@ extern NSString * gBrowserUserAgent; namespace platform { -// If we try to upload our data from the background fetch handler on iOS, we have ~30 seconds to do that gracefully. -static const double kTimeoutInSeconds = 24.0; - -// TODO(AlexZ): Rewrite to use async implementation for better redirects handling and ability to cancel request from destructor. bool HttpClient::RunHttpRequest() { NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL: static_cast<NSURL *>([NSURL URLWithString:@(m_urlRequested.c_str())]) - cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:kTimeoutInSeconds]; + cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:m_timeoutSec]; // We handle cookies manually. request.HTTPShouldHandleCookies = NO; diff --git a/platform/http_client_curl.cpp b/platform/http_client_curl.cpp index 496e3901dd..a8e8e70bf9 100644 --- a/platform/http_client_curl.cpp +++ b/platform/http_client_curl.cpp @@ -190,6 +190,8 @@ bool HttpClient::RunHttpRequest() if (!m_cookies.empty()) cmd += "-b '" + m_cookies + "' "; + cmd += "-m '" + m_timeoutSec + "' "; + if (!m_bodyData.empty()) { body_deleter.m_fileName = GetTmpFileName(); |