New implementation of HTTP protocol class
This commit is contained in:
parent
1de31c96c8
commit
b75a8fe6a8
3 changed files with 775 additions and 241 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -10,6 +10,45 @@
|
|||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
enum class url_schema_type { unknown,
|
||||
http,
|
||||
https,
|
||||
};
|
||||
|
||||
// utl
|
||||
|
||||
url_schema_type identify_url_schema_type(const std::string &schema_name);
|
||||
|
||||
struct url_data {
|
||||
|
||||
url_schema_type schema_type;
|
||||
std::string schema;
|
||||
std::string host;
|
||||
uint16_t port;
|
||||
std::string path;
|
||||
|
||||
url_data() :
|
||||
schema_type(url_schema_type::unknown),
|
||||
port(0) {
|
||||
}
|
||||
url_data(const std::string &url);
|
||||
|
||||
void clear();
|
||||
|
||||
bool parse(const std::string &url);
|
||||
};
|
||||
|
||||
struct http_request {
|
||||
|
||||
std::string body;
|
||||
std::string content_type;
|
||||
|
||||
http_request(const std::string &body_, const std::string &content_type_) :
|
||||
body(body_),
|
||||
content_type(content_type_) {
|
||||
}
|
||||
};
|
||||
|
||||
struct http_response {
|
||||
|
||||
uint16_t status_code;
|
||||
|
|
@ -22,57 +61,74 @@ struct http_response {
|
|||
};
|
||||
|
||||
namespace detail {
|
||||
class https_call_impl;
|
||||
template <class>
|
||||
class http_call_impl;
|
||||
class tcp_socket;
|
||||
class ssl_socket;
|
||||
} // namespace detail
|
||||
|
||||
class https_call {
|
||||
class http_call {
|
||||
public:
|
||||
https_call(const std::string &host, const std::string &ip_addr, uint16_t port, const std::string &method, const std::string &path, const std::string &headers, const std::string &content_type);
|
||||
http_call(const url_data &url, const std::string &method = std::string(), const std::string &headers = std::string());
|
||||
~http_call();
|
||||
|
||||
bool exec(const void *body_data, size_t body_size, http_response *response);
|
||||
bool is_ssl() const;
|
||||
|
||||
const std::string &path() const;
|
||||
void set_path(const std::string &path);
|
||||
void set_method(const std::string &method);
|
||||
void set_headers(const std::string &headers);
|
||||
const std::string &host() const;
|
||||
void set_host(const std::string &host);
|
||||
|
||||
uint16_t port() const;
|
||||
void set_port(uint16_t port);
|
||||
|
||||
bool exec(const http_request &request, http_response *response);
|
||||
|
||||
const std::string &error_what() const;
|
||||
|
||||
private:
|
||||
friend class detail::https_call_impl;
|
||||
static constexpr auto response_size_limit_bytes = 1024 * 1024;
|
||||
template <class>
|
||||
friend class detail::http_call_impl;
|
||||
friend detail::tcp_socket;
|
||||
friend detail::ssl_socket;
|
||||
static constexpr auto response_size_limit_bytes = 1024 * 1024 * 1024;
|
||||
static constexpr auto response_first_alloc_bytes = 32 * 1024;
|
||||
static constexpr auto response_next_alloc_bytes = 256 * 1024;
|
||||
std::string m_host;
|
||||
std::string m_method;
|
||||
uint16_t m_port;
|
||||
std::string m_path;
|
||||
std::string m_method;
|
||||
std::string m_headers;
|
||||
std::string m_content_type;
|
||||
std::string m_error_what;
|
||||
|
||||
boost::asio::io_service m_service;
|
||||
boost::asio::ssl::context m_context;
|
||||
boost::asio::ssl::context *m_context;
|
||||
boost::asio::ip::tcp::endpoint m_endpoint;
|
||||
|
||||
void ctor_priv();
|
||||
};
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
class rpc_client {
|
||||
public:
|
||||
rpc_client(std::string url, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls);
|
||||
rpc_client(const std::string &url, uint16_t port, const std::string &user_name, const std::string &password, bool debug);
|
||||
|
||||
protected:
|
||||
std::string retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx);
|
||||
std::string retrieve_value_from_reply(std::string reply_str, std::string value_path);
|
||||
std::string send_post_request(std::string method, std::string params, bool show_log);
|
||||
|
||||
std::string host;
|
||||
std::string ip;
|
||||
uint32_t port;
|
||||
std::string user;
|
||||
std::string password;
|
||||
bool debug_rpc_calls;
|
||||
|
||||
uint32_t request_id;
|
||||
|
||||
fc::http::header authorization;
|
||||
|
||||
private:
|
||||
https_call *https;
|
||||
//fc::http::reply send_post_request(std::string body, bool show_log);
|
||||
//rpc_reply send_post_request(std::string body, bool show_log);
|
||||
http_response send_post_request(std::string body, bool show_log);
|
||||
http_call client;
|
||||
http_response send_post_request(const std::string &body, bool show_log);
|
||||
};
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -122,8 +122,20 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
|
|||
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
|
||||
}
|
||||
|
||||
node_ip = options.at("hive-node-ip").as<std::string>();
|
||||
node_rpc_port = options.at("hive-node-rpc-port").as<uint32_t>();
|
||||
if ((options.count("hive-node-url") > 0) && (options.count("hive-node-ip") > 0))
|
||||
FC_THROW("both keys are present: hive-node-url and hive-node-ip");
|
||||
|
||||
if (options.count("hive-node-ip"))
|
||||
node_ip = options.at("hive-node-ip").as<std::string>();
|
||||
|
||||
if (options.count("hive-node-url"))
|
||||
node_ip = options.at("hive-node-url").as<std::string>();
|
||||
|
||||
|
||||
if (options.count("hive-node-rpc-port"))
|
||||
node_rpc_port = options.at("hive-node-rpc-port").as<uint32_t>();
|
||||
else
|
||||
node_rpc_port = 0;
|
||||
if (options.count("hive-node-rpc-user")) {
|
||||
node_rpc_user = options.at("hive-node-rpc-user").as<std::string>();
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue