Changes for Beast version 59

This commit is contained in:
Vinnie Falco
2017-06-12 01:03:19 -07:00
committed by Miguel Portilla
parent 49bdf2e72d
commit 61316c7f95
36 changed files with 367 additions and 366 deletions

View File

@@ -102,7 +102,7 @@ OverlayImpl::Timer::run()
timer_.expires_from_now (std::chrono::seconds(1));
timer_.async_wait(overlay_.strand_.wrap(
std::bind(&Timer::on_timer, shared_from_this(),
beast::asio::placeholders::error)));
std::placeholders::_1)));
}
void
@@ -127,7 +127,7 @@ OverlayImpl::Timer::on_timer (error_code ec)
timer_.expires_from_now (std::chrono::seconds(1));
timer_.async_wait(overlay_.strand_.wrap(std::bind(
&Timer::on_timer, shared_from_this(),
beast::asio::placeholders::error)));
std::placeholders::_1)));
}
//------------------------------------------------------------------------------
@@ -219,7 +219,7 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
{
auto const types = beast::rfc2616::split_commas(
request.fields["Connect-As"]);
request["Connect-As"]);
if (std::find_if(types.begin(), types.end(),
[](std::string const& s)
{
@@ -229,12 +229,12 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
handoff.moved = false;
handoff.response = makeRedirectResponse(slot, request,
remote_endpoint.address());
handoff.keep_alive = is_keep_alive(request);
handoff.keep_alive = beast::rfc2616::is_keep_alive(request);
return handoff;
}
}
auto hello = parseHello (true, request.fields, journal);
auto hello = parseHello (true, request, journal);
if(! hello)
{
m_peerFinder->on_closed(slot);
@@ -285,7 +285,7 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
handoff.moved = false;
handoff.response = makeRedirectResponse(slot, request,
remote_endpoint.address());
handoff.keep_alive = is_keep_alive(request);
handoff.keep_alive = beast::rfc2616::is_keep_alive(request);
return handoff;
}
@@ -313,27 +313,39 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
//------------------------------------------------------------------------------
template<class Fields>
static
bool
is_upgrade(beast::http::header<true, Fields> const& req)
{
if(req.version < 11)
return false;
if(req.method() != beast::http::verb::get)
return false;
if(! beast::http::token_list{req["Connection"]}.exists("upgrade"))
return false;
return true;
}
template<class Fields>
static
bool
is_upgrade(beast::http::header<false, Fields> const& req)
{
if(req.version < 11)
return false;
if(! beast::http::token_list{req["Connection"]}.exists("upgrade"))
return false;
return true;
}
bool
OverlayImpl::isPeerUpgrade(http_request_type const& request)
{
if (! is_upgrade(request))
return false;
auto const versions = parse_ProtocolVersions(
request.fields["Upgrade"]);
if (versions.size() == 0)
return false;
return true;
}
bool
OverlayImpl::isPeerUpgrade(http_response_type const& response)
{
if (! is_upgrade(response))
return false;
if(response.status != 101)
return false;
auto const versions = parse_ProtocolVersions(
response.fields["Upgrade"]);
request["Upgrade"]);
if (versions.size() == 0)
return false;
return true;
@@ -353,11 +365,11 @@ OverlayImpl::makeRedirectResponse (PeerFinder::Slot::ptr const& slot,
{
beast::http::response<json_body> msg;
msg.version = request.version;
msg.status = 503;
msg.reason = "Service Unavailable";
msg.fields.insert("Server", BuildInfo::getFullVersionString());
msg.fields.insert("Remote-Address", remote_address.to_string());
msg.fields.insert("Content-Type", "application/json");
msg.result(beast::http::status::service_unavailable);
msg.insert("Server", BuildInfo::getFullVersionString());
msg.insert("Remote-Address", remote_address);
msg.insert("Content-Type", "application/json");
msg.insert(beast::http::field::connection, "close");
msg.body = Json::objectValue;
{
auto const result = m_peerFinder->redirect(slot);
@@ -365,7 +377,7 @@ OverlayImpl::makeRedirectResponse (PeerFinder::Slot::ptr const& slot,
for (auto const& _ : m_peerFinder->redirect(slot))
ips.append(_.address.to_string());
}
prepare(msg, beast::http::connection::close);
msg.prepare();
return std::make_shared<SimpleWriter>(msg);
}
@@ -377,12 +389,12 @@ OverlayImpl::makeErrorResponse (PeerFinder::Slot::ptr const& slot,
{
beast::http::response<beast::http::string_body> msg;
msg.version = request.version;
msg.status = 400;
msg.reason = "Bad Request";
msg.fields.insert("Server", BuildInfo::getFullVersionString());
msg.fields.insert("Remote-Address", remote_address.to_string());
msg.result(beast::http::status::bad_request);
msg.insert("Server", BuildInfo::getFullVersionString());
msg.insert("Remote-Address", remote_address.to_string());
msg.insert(beast::http::field::connection, "close");
msg.body = text;
prepare(msg, beast::http::connection::close);
msg.prepare();
return std::make_shared<SimpleWriter>(msg);
}
@@ -827,17 +839,17 @@ bool
OverlayImpl::processRequest (http_request_type const& req,
Handoff& handoff)
{
if (req.url != "/crawl")
if (req.target() != "/crawl")
return false;
beast::http::response<json_body> msg;
msg.version = req.version;
msg.status = 200;
msg.reason = "OK";
msg.fields.insert("Server", BuildInfo::getFullVersionString());
msg.fields.insert("Content-Type", "application/json");
msg.result(beast::http::status::ok);
msg.insert("Server", BuildInfo::getFullVersionString());
msg.insert("Content-Type", "application/json");
msg.insert("Connection", "close");
msg.body["overlay"] = crawl();
prepare(msg, beast::http::connection::close);
msg.prepare();
handoff.response = std::make_shared<SimpleWriter>(msg);
return true;
}