Fix use-after-move in example request handlers

fix #992
This commit is contained in:
Vinnie Falco
2018-01-22 11:57:00 -08:00
parent 4fb535ece6
commit 72cf7db931
12 changed files with 56 additions and 22 deletions
@@ -180,13 +180,16 @@ handle_request(
if(ec)
return send(server_error(ec.message()));
// Cache the size since we need it after the move
auto const size = body.size();
// Respond to HEAD request
if(req.method() == http::verb::head)
{
http::response<http::empty_body> res{http::status::ok, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, mime_type(path));
res.content_length(body.size());
res.content_length(size);
res.keep_alive(req.keep_alive());
return send(std::move(res));
}
@@ -198,7 +201,7 @@ handle_request(
std::make_tuple(http::status::ok, req.version())};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, mime_type(path));
res.content_length(body.size());
res.content_length(size);
res.keep_alive(req.keep_alive());
return send(std::move(res));
}