Refactor prepare (API Change)

This commit is contained in:
Vinnie Falco
2017-07-20 08:12:18 -07:00
parent 2af19481a9
commit 2df6783468
26 changed files with 543 additions and 362 deletions
+5 -5
View File
@@ -449,9 +449,10 @@ do_head_request(
@param transform The header transformation to apply. The function will
be called with this signature:
@code
void transform(
header<isRequest, Fields>&, // The header to transform
error_code&); // Set to the error, if any
template<class Body>
void transform(message<
isRequest, Body, Fields>&, // The message to transform
error_code&); // Set to the error, if any
@endcode
@param ec Set to the error if any occurred.
@@ -496,8 +497,7 @@ relay(
return;
// Apply the caller's header tranformation
// base() returns a reference to the header portion of the message.
transform(p.get().base(), ec);
transform(p.get(), ec);
if(ec)
return;
+10 -6
View File
@@ -24,6 +24,16 @@ struct file_body
{
using value_type = std::string;
/// Returns the content length of the body in a message.
template<bool isRequest, class Fields>
static
std::uint64_t
size(
message<isRequest, file_body, Fields> const& m)
{
return boost::filesystem::file_size(m.body.c_str());
}
class reader
{
std::uint64_t size_ = 0;
@@ -67,12 +77,6 @@ struct file_body
size_ = boost::filesystem::file_size(path_);
}
std::uint64_t
content_length() const
{
return size_;
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
+3 -3
View File
@@ -239,7 +239,7 @@ private:
res.insert("Server", "http_async_server");
res.insert("Content-Type", "text/html");
res.body = "The file '" + path + "' was not found";
prepare(res);
res.prepare();
async_write(sock_, std::move(res),
std::bind(&peer::on_write, shared_from_this(),
std::placeholders::_1));
@@ -253,7 +253,7 @@ private:
res.insert("Server", "http_async_server");
res.insert("Content-Type", mime_type(path));
res.body = path;
prepare(res);
res.prepare();
async_write(sock_, std::move(res),
std::bind(&peer::on_write, shared_from_this(),
std::placeholders::_1));
@@ -267,7 +267,7 @@ private:
res.insert("Content-Type", "text/html");
res.body =
std::string{"An internal error occurred"} + e.what();
prepare(res);
res.prepare();
async_write(sock_, std::move(res),
std::bind(&peer::on_write, shared_from_this(),
std::placeholders::_1));
+2 -2
View File
@@ -38,12 +38,12 @@ int main(int, char const*[])
auto ep = sock.remote_endpoint();
request<string_body> req;
req.method(verb::get);
req.target("/");
req.version = 11;
req.target("/");
req.insert("Host", host + std::string(":") +
boost::lexical_cast<std::string>(ep.port()));
req.insert("User-Agent", "beast/http");
prepare(req);
req.prepare();
write(sock, req);
response<string_body> res;
beast::multi_buffer b;
+1 -1
View File
@@ -32,7 +32,7 @@ int main()
req.replace("Host", host + ":" +
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
req.replace("User-Agent", "Beast");
beast::http::prepare(req);
req.prepare();
beast::http::write(sock, req);
// Receive and print HTTP response using beast
+3 -3
View File
@@ -169,7 +169,7 @@ private:
res.insert("Server", "http_sync_server");
res.insert("Content-Type", "text/html");
res.body = "The file '" + path + "' was not found";
prepare(res);
res.prepare();
write(sock, res, ec);
if(ec)
break;
@@ -184,7 +184,7 @@ private:
res.insert("Server", "http_sync_server");
res.insert("Content-Type", mime_type(path));
res.body = path;
prepare(res);
res.prepare();
write(sock, res, ec);
if(ec)
break;
@@ -199,7 +199,7 @@ private:
res.insert("Content-Type", "text/html");
res.body =
std::string{"An internal error occurred: "} + e.what();
prepare(res);
res.prepare();
write(sock, res, ec);
if(ec)
break;
+1 -1
View File
@@ -41,7 +41,7 @@ int main()
req.insert("Host", host + ":" +
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
req.insert("User-Agent", "Beast");
beast::http::prepare(req);
req.prepare();
beast::http::write(stream, req);
// Receive and print HTTP response using Beast