diff options
author | Lee Clagett <code@leeclagett.com> | 2017-01-25 00:16:05 -0500 |
---|---|---|
committer | Lee Clagett <code@leeclagett.com> | 2017-01-25 15:39:32 -0500 |
commit | c02e1cb943903d34becfaf1c6d9cd71e4424d748 (patch) | |
tree | a363ce155ba8f6b14a924c84380ec2886894f22d /contrib/epee/include/storages/http_abstract_invoke.h | |
parent | Merge pull request #1622 (diff) | |
download | monero-c02e1cb943903d34becfaf1c6d9cd71e4424d748.tar.xz |
Updates to epee HTTP client code
- http_simple_client now uses std::chrono for timeouts
- http_simple_client accepts timeouts per connect / invoke call
- shortened names of epee http invoke functions
- invoke command functions only take relative path, connection
is not automatically performed
Diffstat (limited to 'contrib/epee/include/storages/http_abstract_invoke.h')
-rw-r--r-- | contrib/epee/include/storages/http_abstract_invoke.h | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/contrib/epee/include/storages/http_abstract_invoke.h b/contrib/epee/include/storages/http_abstract_invoke.h index 00ee8a4ad..36177c7e0 100644 --- a/contrib/epee/include/storages/http_abstract_invoke.h +++ b/contrib/epee/include/storages/http_abstract_invoke.h @@ -35,28 +35,28 @@ namespace epee namespace net_utils { template<class t_request, class t_response, class t_transport> - bool invoke_http_json_remote_command2(const std::string& url, t_request& out_struct, t_response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& method = "GET") + bool invoke_http_json(const std::string& uri, const t_request& out_struct, t_response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(5), const std::string& method = "GET") { std::string req_param; if(!serialization::store_t_to_json(out_struct, req_param)) return false; const http::http_response_info* pri = NULL; - if(!invoke_request(url, transport, timeout, &pri, method, req_param)) + if(!transport.invoke(uri, method, req_param, timeout, std::addressof(pri))) { - LOG_PRINT_L1("Failed to invoke http request to " << url); + LOG_PRINT_L1("Failed to invoke http request to " << uri); return false; } - if(!pri->m_response_code) + if(!pri) { - LOG_PRINT_L1("Failed to invoke http request to " << url << ", internal error (null response ptr)"); + LOG_PRINT_L1("Failed to invoke http request to " << uri << ", internal error (null response ptr)"); return false; } if(pri->m_response_code != 200) { - LOG_PRINT_L1("Failed to invoke http request to " << url << ", wrong response code: " << pri->m_response_code); + LOG_PRINT_L1("Failed to invoke http request to " << uri << ", wrong response code: " << pri->m_response_code); return false; } @@ -66,28 +66,28 @@ namespace epee template<class t_request, class t_response, class t_transport> - bool invoke_http_bin_remote_command2(const std::string& url, t_request& out_struct, t_response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& method = "GET") + bool invoke_http_bin(const std::string& uri, const t_request& out_struct, t_response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(5), const std::string& method = "GET") { std::string req_param; if(!serialization::store_t_to_binary(out_struct, req_param)) return false; const http::http_response_info* pri = NULL; - if(!invoke_request(url, transport, timeout, &pri, method, req_param)) + if(!transport.invoke(uri, method, req_param, timeout, std::addressof(pri))) { - LOG_PRINT_L1("Failed to invoke http request to " << url); + LOG_PRINT_L1("Failed to invoke http request to " << uri); return false; } - if(!pri->m_response_code) + if(!pri) { - LOG_PRINT_L1("Failed to invoke http request to " << url << ", internal error (null response ptr)"); + LOG_PRINT_L1("Failed to invoke http request to " << uri << ", internal error (null response ptr)"); return false; } if(pri->m_response_code != 200) { - LOG_PRINT_L1("Failed to invoke http request to " << url << ", wrong response code: " << pri->m_response_code); + LOG_PRINT_L1("Failed to invoke http request to " << uri << ", wrong response code: " << pri->m_response_code); return false; } @@ -95,15 +95,15 @@ namespace epee } template<class t_request, class t_response, class t_transport> - bool invoke_http_json_rpc(const std::string& url, const std::string& method_name, t_request& out_struct, t_response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& http_method = "GET", const std::string& req_id = "0") + bool invoke_http_json_rpc(const std::string& uri, std::string method_name, const t_request& out_struct, t_response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(5), const std::string& http_method = "GET", const std::string& req_id = "0") { epee::json_rpc::request<t_request> req_t = AUTO_VAL_INIT(req_t); req_t.jsonrpc = "2.0"; req_t.id = req_id; - req_t.method = method_name; + req_t.method = std::move(method_name); req_t.params = out_struct; epee::json_rpc::response<t_response, epee::json_rpc::error> resp_t = AUTO_VAL_INIT(resp_t); - if(!epee::net_utils::invoke_http_json_remote_command2(url, req_t, resp_t, transport, timeout, http_method)) + if(!epee::net_utils::invoke_http_json(uri, req_t, resp_t, transport, timeout, http_method)) { return false; } @@ -117,9 +117,9 @@ namespace epee } template<class t_command, class t_transport> - bool invoke_http_json_rpc(const std::string& url, typename t_command::request& out_struct, typename t_command::response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& http_method = "GET", const std::string& req_id = "0") + bool invoke_http_json_rpc(const std::string& uri, typename t_command::request& out_struct, typename t_command::response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(5), const std::string& http_method = "GET", const std::string& req_id = "0") { - return invoke_http_json_rpc(url, t_command::methodname(), out_struct, result_struct, transport, timeout, http_method, req_id); + return invoke_http_json_rpc(uri, t_command::methodname(), out_struct, result_struct, transport, timeout, http_method, req_id); } } |