Use content_length method for setting the Content-Length header

Boost.Beast changed the signature of the previously used generic `set`
method so that it no longer accepts integer types, however there is
alreay a more specific method for setting the Content-Length header, so
use this one instead.
This commit is contained in:
Julian Brost 2020-12-22 14:32:56 +01:00
parent 6145525482
commit 339b37a985
6 changed files with 10 additions and 10 deletions

View File

@ -494,7 +494,7 @@ void ElasticsearchWriter::SendRequest(const String& body)
request.set(http::field::authorization, "Basic " + Base64::Encode(username + ":" + password));
request.body() = body;
request.set(http::field::content_length, request.body().size());
request.content_length(request.body().size());
/* Don't log the request body to debug log, this is already done above. */
Log(LogDebug, "ElasticsearchWriter")

View File

@ -517,7 +517,7 @@ void InfluxdbWriter::Flush()
}
request.body() = body;
request.set(http::field::content_length, request.body().size());
request.content_length(request.body().size());
try {
if (stream.first) {

View File

@ -84,7 +84,7 @@ bool ConfigFilesHandler::HandleRequest(
response.result(http::status::ok);
response.set(http::field::content_type, "application/octet-stream");
response.body() = content;
response.set(http::field::content_length, response.body().size());
response.content_length(response.body().size());
} catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, params, 500, "Could not read file.",
DiagnosticInformation(ex));

View File

@ -186,7 +186,7 @@ bool EnsureValidHeaders(
} else {
response.set(http::field::content_type, "text/html");
response.body() = String("<h1>Bad Request</h1><p><pre>") + errorMsg + "</pre></p>";
response.set(http::field::content_length, response.body().size());
response.content_length(response.body().size());
}
response.set(http::field::connection, "close");
@ -259,7 +259,7 @@ bool HandleAccessControl(
response.set(http::field::access_control_allow_methods, "GET, POST, PUT, DELETE");
response.set(http::field::access_control_allow_headers, "Authorization, Content-Type, X-HTTP-Method-Override");
response.body() = "Preflight OK";
response.set(http::field::content_length, response.body().size());
response.content_length(response.body().size());
response.set(http::field::connection, "close");
boost::system::error_code ec;
@ -290,7 +290,7 @@ bool EnsureAcceptHeader(
response.result(http::status::bad_request);
response.set(http::field::content_type, "text/html");
response.body() = "<h1>Accept header is missing or not set to 'application/json'.</h1>";
response.set(http::field::content_length, response.body().size());
response.content_length(response.body().size());
response.set(http::field::connection, "close");
boost::system::error_code ec;
@ -331,7 +331,7 @@ bool EnsureAuthenticatedUser(
} else {
response.set(http::field::content_type, "text/html");
response.body() = "<h1>Unauthorized. Please check your user credentials.</h1>";
response.set(http::field::content_length, response.body().size());
response.content_length(response.body().size());
}
boost::system::error_code ec;
@ -423,7 +423,7 @@ bool EnsureValidBody(
} else {
response.set(http::field::content_type, "text/html");
response.body() = String("<h1>Bad Request</h1><p><pre>") + ec.message() + "</pre></p>";
response.set(http::field::content_length, response.body().size());
response.content_length(response.body().size());
}
response.set(http::field::connection, "close");

View File

@ -58,7 +58,7 @@ void HttpUtility::SendJsonBody(boost::beast::http::response<boost::beast::http::
response.set(http::field::content_type, "application/json");
response.body() = JsonEncode(val, params && GetLastParameter(params, "pretty"));
response.set(http::field::content_length, response.body().size());
response.content_length(response.body().size());
}
void HttpUtility::SendJsonError(boost::beast::http::response<boost::beast::http::string_body>& response,

View File

@ -92,7 +92,7 @@ bool InfoHandler::HandleRequest(
body += R"(<p>More information about API requests is available in the <a href="https://icinga.com/docs/icinga2/latest/" target="_blank">documentation</a>.</p></html>)";
response.body() = body;
response.set(http::field::content_length, response.body().size());
response.content_length(response.body().size());
}
return true;