forked from boostorg/beast
Refactor header and message constructors:
fix #581 * request and response headers now have convenience constructors so important fields like method, target, result, and version may be set upon construction. Actions Required: * Evaluate each message constructor call site and adjust the constructor argument list as needed.
This commit is contained in:
@@ -48,10 +48,7 @@ int main()
|
||||
return fail("connect", ec);
|
||||
|
||||
// Set up an HTTP GET request message
|
||||
http::request<http::string_body> req;
|
||||
req.method(http::verb::get);
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
http::request<http::string_body> req{http::verb::get, "/", 11};
|
||||
req.set(http::field::host, host + ":" +
|
||||
std::to_string(sock.remote_endpoint().port()));
|
||||
req.set(http::field::user_agent, BEAST_VERSION_STRING);
|
||||
|
||||
@@ -75,10 +75,7 @@ main(int, char const*[])
|
||||
}
|
||||
|
||||
// Set up an HTTP GET request
|
||||
http::request<http::string_body> req;
|
||||
req.version = 11;
|
||||
req.method(http::verb::get);
|
||||
req.target("/");
|
||||
http::request<http::string_body> req{http::verb::get, "/", 11};
|
||||
req.set(http::field::host, host + std::string(":") + std::to_string(ep.port()));
|
||||
req.set(http::field::user_agent, BEAST_VERSION_STRING);
|
||||
|
||||
|
||||
@@ -60,8 +60,7 @@ private:
|
||||
http::response<http::string_view_body>
|
||||
client_error(http::status result, beast::string_view text)
|
||||
{
|
||||
http::response<http::string_view_body> res;
|
||||
res.result(result);
|
||||
http::response<http::string_view_body> res{result, 11};
|
||||
res.set(http::field::server, BEAST_VERSION_STRING);
|
||||
res.set(http::field::content_type, "text/plain");
|
||||
res.set(http::field::connection, "close");
|
||||
@@ -75,8 +74,7 @@ private:
|
||||
beast::http::response<beast::http::string_body>
|
||||
not_found() const
|
||||
{
|
||||
beast::http::response<beast::http::string_body> res;
|
||||
res.result(beast::http::status::not_found);
|
||||
beast::http::response<beast::http::string_body> res{beast::http::status::not_found, 11};
|
||||
res.set(beast::http::field::server, BEAST_VERSION_STRING);
|
||||
res.set(beast::http::field::content_type, "text/html");
|
||||
res.set(http::field::connection, "close");
|
||||
@@ -90,8 +88,7 @@ private:
|
||||
beast::http::response<beast::http::string_body>
|
||||
server_error(beast::error_code const& ec) const
|
||||
{
|
||||
beast::http::response<beast::http::string_body> res;
|
||||
res.result(beast::http::status::internal_server_error);
|
||||
beast::http::response<beast::http::string_body> res{beast::http::status::internal_server_error, 11};
|
||||
res.set(beast::http::field::server, BEAST_VERSION_STRING);
|
||||
res.set(beast::http::field::content_type, "text/html");
|
||||
res.set(http::field::connection, "close");
|
||||
|
||||
@@ -264,7 +264,7 @@ protected:
|
||||
// We construct the dynamic body with a 1MB limit
|
||||
// to prevent vulnerability to buffer attacks.
|
||||
//
|
||||
parser_.emplace(1024 * 1024);
|
||||
parser_.emplace(std::piecewise_construct, std::make_tuple(1024 * 1024));
|
||||
|
||||
// Read just the header
|
||||
beast::http::async_read_header(
|
||||
|
||||
@@ -188,7 +188,8 @@ private:
|
||||
// We construct the dynamic body with a 1MB limit
|
||||
// to prevent vulnerability to buffer attacks.
|
||||
//
|
||||
beast::http::request_parser<beast::http::dynamic_body> parser(1024* 1024);
|
||||
beast::http::request_parser<beast::http::dynamic_body> parser(
|
||||
std::piecewise_construct, std::make_tuple(1024* 1024));
|
||||
|
||||
// Read the header first
|
||||
beast::http::read_header(impl().stream(), buffer_, parser, ec);
|
||||
|
||||
Reference in New Issue
Block a user