diff options
author | lloyd <[email protected]> | 2013-11-29 22:05:33 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2013-11-29 22:05:33 +0000 |
commit | 41cc764815c5cdf1902e923b7bea3f3eec288c31 (patch) | |
tree | 93d411094a177cb858b000357816e9bf079ff787 | |
parent | a71747c510c5be81af200a41e2268a021b4580f2 (diff) |
Remove timeout from HTTP
-rw-r--r-- | src/utils/http_util/http_util.cpp | 26 | ||||
-rw-r--r-- | src/utils/http_util/http_util.h | 13 |
2 files changed, 16 insertions, 23 deletions
diff --git a/src/utils/http_util/http_util.cpp b/src/utils/http_util/http_util.cpp index 5e321d54b..2a02e1280 100644 --- a/src/utils/http_util/http_util.cpp +++ b/src/utils/http_util/http_util.cpp @@ -42,7 +42,6 @@ Response http_sync(const std::string& verb, const std::string& url, const std::string& content_type, const std::vector<byte>& body, - std::chrono::milliseconds timeout, size_t allowable_redirects) { using namespace boost::asio::ip; @@ -51,8 +50,6 @@ Response http_sync(const std::string& verb, if(protocol_host_sep == std::string::npos) throw std::runtime_error("Invalid URL " + url); const std::string protocol = url.substr(0, protocol_host_sep); - if(protocol != "http") - throw std::runtime_error("Unsupported protocol " + protocol); const auto host_loc_sep = url.find('/', protocol_host_sep + 3); @@ -71,10 +68,7 @@ Response http_sync(const std::string& verb, tcp::iostream sock; - if(timeout.count()) - sock.expires_from_now(boost::posix_time::milliseconds(timeout.count())); - - sock.connect(hostname, protocol); + sock.connect(hostname, "http"); if(!sock) throw std::runtime_error("Connection to " + hostname + " failed"); @@ -132,7 +126,7 @@ Response http_sync(const std::string& verb, { if(allowable_redirects == 0) throw std::runtime_error("HTTP redirection count exceeded"); - return GET_sync(headers["Location"], timeout, allowable_redirects - 1); + return GET_sync(headers["Location"], allowable_redirects - 1); } // Use Content-Length if set @@ -147,28 +141,22 @@ Response http_sync(const std::string& verb, return Response(status_code, status_message, resp_body, headers); } -Response GET_sync(const std::string& url, - std::chrono::milliseconds timeout, - size_t allowable_redirects) +Response GET_sync(const std::string& url, size_t allowable_redirects) { - return http_sync("GET", url, "", std::vector<byte>(), - timeout, allowable_redirects); + return http_sync("GET", url, "", std::vector<byte>(), allowable_redirects); } Response POST_sync(const std::string& url, const std::string& content_type, const std::vector<byte>& body, - std::chrono::milliseconds timeout, size_t allowable_redirects) { - return http_sync("POST", url, content_type, body, - timeout, allowable_redirects); + return http_sync("POST", url, content_type, body, allowable_redirects); } -std::future<Response> GET_async(const std::string& url) +std::future<Response> GET_async(const std::string& url, size_t allowable_redirects) { - return std::async(std::launch::async, GET_sync, url, - std::chrono::seconds(5), 1); + return std::async(std::launch::async, GET_sync, url, allowable_redirects); } } diff --git a/src/utils/http_util/http_util.h b/src/utils/http_util/http_util.h index a69bc3cd9..37fe3bb36 100644 --- a/src/utils/http_util/http_util.h +++ b/src/utils/http_util/http_util.h @@ -37,6 +37,13 @@ struct Response const std::map<std::string, std::string>& headers() const { return m_headers; } std::string status_message() const { return m_status_message; } + + void throw_unless_ok() + { + if(status_code() != 200) + throw std::runtime_error("HTTP error: " + status_message()); + } + private: unsigned int m_status_code; std::string m_status_message; @@ -48,20 +55,18 @@ BOTAN_DLL Response http_sync(const std::string& verb, const std::string& url, const std::string& content_type, const std::vector<byte>& body, - std::chrono::milliseconds timeout, size_t allowable_redirects); BOTAN_DLL Response GET_sync(const std::string& url, - std::chrono::milliseconds timeout = std::chrono::seconds(5), size_t allowable_redirects = 1); BOTAN_DLL Response POST_sync(const std::string& url, const std::string& content_type, const std::vector<byte>& body, - std::chrono::milliseconds timeout = std::chrono::seconds(5), size_t allowable_redirects = 1); -BOTAN_DLL std::future<Response> BOTAN_DLL GET_async(const std::string& url); +BOTAN_DLL std::future<Response> BOTAN_DLL GET_async(const std::string& url, + size_t allowable_redirects = 1); BOTAN_DLL std::string url_encode(const std::string& url); |