message::body is a member function (API Change):

fix #778

* The body data member is replaced with accessor
  member functions.

Actions Required:

* Call member function message::body instead of accessing
  the data member at call sites.
This commit is contained in:
Vinnie Falco
2017-09-12 17:12:12 -07:00
parent 0d4d239d05
commit 54fe7cacf7
36 changed files with 248 additions and 182 deletions
@@ -124,7 +124,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -137,7 +137,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -150,7 +150,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
+3 -3
View File
@@ -118,7 +118,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -131,7 +131,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -144,7 +144,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
+19 -19
View File
@@ -210,8 +210,8 @@ send_cgi_response(
// that it might be coming later. Otherwise the
// serializer::is_done would return true right after
// sending the header.
res.body.data = nullptr;
res.body.more = true;
res.body().data = nullptr;
res.body().more = true;
// Create the serializer.
response_serializer<buffer_body, fields> sr{res};
@@ -235,10 +235,10 @@ send_cgi_response(
ec = {};
// `nullptr` indicates there is no buffer
res.body.data = nullptr;
res.body().data = nullptr;
// `false` means no more data is coming
res.body.more = false;
res.body().more = false;
}
else
{
@@ -248,9 +248,9 @@ send_cgi_response(
// Point to our buffer with the bytes that
// we received, and indicate that there may
// be some more data coming
res.body.data = buffer;
res.body.size = bytes_transferred;
res.body.more = true;
res.body().data = buffer;
res.body().size = bytes_transferred;
res.body().more = true;
}
// Write everything in the body buffer
@@ -328,7 +328,7 @@ void do_server_head(
// We deliver the same payload for GET requests
// regardless of the target. A real server might
// deliver a file based on the target.
res.body = payload;
res.body() = payload;
}
break;
}
@@ -339,7 +339,7 @@ void do_server_head(
// we do not recognize the request method.
res.result(status::bad_request);
res.set(field::content_type, "text/plain");
res.body = "Invalid request-method '" + req.method_string().to_string() + "'";
res.body() = "Invalid request-method '" + req.method_string().to_string() + "'";
res.prepare_payload();
break;
}
@@ -520,8 +520,8 @@ relay(
if(! p.is_done())
{
// Set up the body for writing into our small buffer
p.get().body.data = buf;
p.get().body.size = sizeof(buf);
p.get().body().data = buf;
p.get().body().size = sizeof(buf);
// Read as much as we can
read(input, buffer, p, ec);
@@ -534,14 +534,14 @@ relay(
// Set up the body for reading.
// This is how much was parsed:
p.get().body.size = sizeof(buf) - p.get().body.size;
p.get().body.data = buf;
p.get().body.more = ! p.is_done();
p.get().body().size = sizeof(buf) - p.get().body().size;
p.get().body().data = buf;
p.get().body().more = ! p.is_done();
}
else
{
p.get().body.data = nullptr;
p.get().body.size = 0;
p.get().body().data = nullptr;
p.get().body().size = 0;
}
// Write everything in the buffer (which might be empty)
@@ -1095,14 +1095,14 @@ read_and_print_body(
while(! p.is_done())
{
char buf[512];
p.get().body.data = buf;
p.get().body.size = sizeof(buf);
p.get().body().data = buf;
p.get().body().size = sizeof(buf);
read(stream, buffer, p, ec);
if(ec == error::need_buffer)
ec.assign(0, ec.category());
if(ec)
return;
os.write(buf, sizeof(buf) - p.get().body.size);
os.write(buf, sizeof(buf) - p.get().body().size);
}
}
@@ -119,7 +119,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -132,7 +132,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -145,7 +145,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
@@ -115,7 +115,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -128,7 +128,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -141,7 +141,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
@@ -118,7 +118,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -131,7 +131,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -144,7 +144,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
@@ -114,7 +114,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -127,7 +127,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -140,7 +140,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
@@ -212,7 +212,7 @@ private:
string_response_->set(http::field::server, "Beast");
string_response_->set(http::field::connection, "close");
string_response_->set(http::field::content_type, "text/plain");
string_response_->body = error;
string_response_->body() = error;
string_response_->prepare_payload();
string_serializer_.emplace(*string_response_);
@@ -268,7 +268,7 @@ private:
file_response_->set(http::field::server, "Beast");
file_response_->set(http::field::connection, "close");
file_response_->set(http::field::content_type, mime_type(target.to_string()));
file_response_->body = std::move(file);
file_response_->body() = std::move(file);
file_response_->prepare_payload();
file_serializer_.emplace(*file_response_);
@@ -119,7 +119,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -132,7 +132,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -145,7 +145,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
@@ -116,7 +116,7 @@ private:
// we do not recognize the request method.
response_.result(http::status::bad_request);
response_.set(http::field::content_type, "text/plain");
boost::beast::ostream(response_.body)
boost::beast::ostream(response_.body())
<< "Invalid request-method '"
<< request_.method_string().to_string()
<< "'";
@@ -133,7 +133,7 @@ private:
if(request_.target() == "/count")
{
response_.set(http::field::content_type, "text/html");
boost::beast::ostream(response_.body)
boost::beast::ostream(response_.body())
<< "<html>\n"
<< "<head><title>Request count</title></head>\n"
<< "<body>\n"
@@ -147,7 +147,7 @@ private:
else if(request_.target() == "/time")
{
response_.set(http::field::content_type, "text/html");
boost::beast::ostream(response_.body)
boost::beast::ostream(response_.body())
<< "<html>\n"
<< "<head><title>Current time</title></head>\n"
<< "<body>\n"
@@ -162,7 +162,7 @@ private:
{
response_.result(http::status::not_found);
response_.set(http::field::content_type, "text/plain");
boost::beast::ostream(response_.body) << "File not found\r\n";
boost::beast::ostream(response_.body()) << "File not found\r\n";
}
}
@@ -172,7 +172,7 @@ private:
{
auto self = shared_from_this();
response_.set(http::field::content_length, response_.body.size());
response_.set(http::field::content_length, response_.body().size());
http::async_write(
socket_,
@@ -120,7 +120,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -133,7 +133,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -146,7 +146,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
@@ -116,7 +116,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -129,7 +129,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -142,7 +142,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
@@ -115,7 +115,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -128,7 +128,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -141,7 +141,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};
@@ -113,7 +113,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = why.to_string();
res.body() = why.to_string();
res.prepare_payload();
return res;
};
@@ -126,7 +126,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "The resource '" + target.to_string() + "' was not found.";
res.body() = "The resource '" + target.to_string() + "' was not found.";
res.prepare_payload();
return res;
};
@@ -139,7 +139,7 @@ handle_request(
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body = "An error occurred: '" + what.to_string() + "'";
res.body() = "An error occurred: '" + what.to_string() + "'";
res.prepare_payload();
return res;
};