Convert code to use boost::beast

This commit is contained in:
seelabs
2018-04-17 14:56:24 -04:00
parent 2ac1c2b433
commit 27703859e7
71 changed files with 513 additions and 464 deletions

View File

@@ -19,14 +19,13 @@
#ifndef RIPPLE_TEST_TRUSTED_PUBLISHER_SERVER_H_INCLUDED
#define RIPPLE_TEST_TRUSTED_PUBLISHER_SERVER_H_INCLUDED
#include <beast/core/detail/base64.hpp>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/Sign.h>
#include <ripple/basics/strHex.h>
#include <boost/asio.hpp>
#include <beast/core/detail/base64.hpp>
#include <beast/http.hpp>
#include <boost/beast/core/detail/base64.hpp>
#include <boost/beast/http.hpp>
namespace ripple {
namespace test {
@@ -37,8 +36,8 @@ class TrustedPublisherServer
using address_type = boost::asio::ip::address;
using socket_type = boost::asio::ip::tcp::socket;
using req_type = beast::http::request<beast::http::string_body>;
using resp_type = beast::http::response<beast::http::string_body>;
using req_type = boost::beast::http::request<boost::beast::http::string_body>;
using resp_type = boost::beast::http::response<boost::beast::http::string_body>;
using error_code = boost::system::error_code;
socket_type sock_;
@@ -78,7 +77,7 @@ public:
}
data.pop_back();
data += "]}";
std::string blob = beast::detail::base64_encode(data);
std::string blob = boost::beast::detail::base64_encode(data);
list_ = "{\"blob\":\"" + blob + "\"";
@@ -155,35 +154,35 @@ private:
do_peer(int id, socket_type&& sock0)
{
socket_type sock(std::move(sock0));
beast::multi_buffer sb;
boost::beast::multi_buffer sb;
error_code ec;
for (;;)
{
req_type req;
beast::http::read(sock, sb, req, ec);
boost::beast::http::read(sock, sb, req, ec);
if (ec)
break;
auto path = req.target().to_string();
if (path != "/validators")
{
resp_type res;
res.result(beast::http::status::not_found);
res.version = req.version;
res.result(boost::beast::http::status::not_found);
res.version(req.version());
res.insert("Server", "TrustedPublisherServer");
res.insert("Content-Type", "text/html");
res.body = "The file '" + path + "' was not found";
res.body() = "The file '" + path + "' was not found";
res.prepare_payload();
write(sock, res, ec);
if (ec)
break;
}
resp_type res;
res.result(beast::http::status::ok);
res.version = req.version;
res.result(boost::beast::http::status::ok);
res.version(req.version());
res.insert("Server", "TrustedPublisherServer");
res.insert("Content-Type", "application/json");
res.body = list_;
res.body() = list_;
try
{
res.prepare_payload();
@@ -191,11 +190,11 @@ private:
catch (std::exception const& e)
{
res = {};
res.result(beast::http::status::internal_server_error);
res.version = req.version;
res.result(boost::beast::http::status::internal_server_error);
res.version(req.version());
res.insert("Server", "TrustedPublisherServer");
res.insert("Content-Type", "text/html");
res.body = std::string{"An internal error occurred"} + e.what();
res.body() = std::string{"An internal error occurred"} + e.what();
res.prepare_payload();
}
write(sock, res, ec);