diff options
author | Jack Lloyd <[email protected]> | 2017-12-16 13:32:56 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-12-17 14:59:21 -0500 |
commit | 9a314557b1e38c63bcf8a404ebf31248a9402015 (patch) | |
tree | 5099ba8846f9020976785f33e6233829caeb0abe /src/lib/utils/http_util/http_util.cpp | |
parent | bcfd2761679d79471612bdf7f500b87123c1c6ab (diff) |
Expose timeouts to the HTTP API
Diffstat (limited to 'src/lib/utils/http_util/http_util.cpp')
-rw-r--r-- | src/lib/utils/http_util/http_util.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp index 55dbd4df6..40e1dc976 100644 --- a/src/lib/utils/http_util/http_util.cpp +++ b/src/lib/utils/http_util/http_util.cpp @@ -25,13 +25,14 @@ namespace { * closes the socket. */ std::string http_transact(const std::string& hostname, - const std::string& message) + const std::string& message, + std::chrono::milliseconds timeout) { std::unique_ptr<OS::Socket> socket; try { - socket = OS::open_socket(hostname, "http", std::chrono::milliseconds(2500)); + socket = OS::open_socket(hostname, "http", timeout); if(!socket) throw Exception("No socket support enabled in build"); } @@ -205,10 +206,17 @@ Response http_sync(const std::string& verb, const std::string& url, const std::string& content_type, const std::vector<uint8_t>& body, - size_t allowable_redirects) + size_t allowable_redirects, + std::chrono::milliseconds timeout) { + auto transact_with_timeout = + [timeout](const std::string& hostname, const std::string& service) + { + return http_transact(hostname, service, timeout); + }; + return http_sync( - http_transact, + transact_with_timeout, verb, url, content_type, @@ -216,17 +224,20 @@ Response http_sync(const std::string& verb, allowable_redirects); } -Response GET_sync(const std::string& url, size_t allowable_redirects) +Response GET_sync(const std::string& url, + size_t allowable_redirects, + std::chrono::milliseconds timeout) { - return http_sync("GET", url, "", std::vector<uint8_t>(), allowable_redirects); + return http_sync("GET", url, "", std::vector<uint8_t>(), allowable_redirects, timeout); } Response POST_sync(const std::string& url, const std::string& content_type, const std::vector<uint8_t>& body, - size_t allowable_redirects) + size_t allowable_redirects, + std::chrono::milliseconds timeout) { - return http_sync("POST", url, content_type, body, allowable_redirects); + return http_sync("POST", url, content_type, body, allowable_redirects, timeout); } } |