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

View File

@ -6,6 +6,7 @@ Version 153:
* Update README.md for branches
* Avoid string_view::clear
* Fix iterator version of basic_fields::erase
* Fix use-after-move in example request handlers
--------------------------------------------------------------------------------

View File

@ -185,13 +185,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));
}
@ -203,7 +206,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));
}

View File

@ -179,13 +179,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));
}
@ -197,7 +200,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));
}

View File

@ -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));
}

View File

@ -176,13 +176,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));
}
@ -194,7 +197,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));
}

View File

@ -178,13 +178,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));
}
@ -196,7 +199,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));
}

View File

@ -174,13 +174,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));
}
@ -192,7 +195,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));
}

View File

@ -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));
}

View File

@ -181,13 +181,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));
}
@ -199,7 +202,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));
}

View File

@ -177,13 +177,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));
}
@ -195,7 +198,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));
}

View File

@ -175,13 +175,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));
}
@ -193,7 +196,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));
}

View File

@ -173,13 +173,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));
}
@ -191,7 +194,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));
}